[Tex/LaTex] Spurious spaces in tabular environment with siunitx and percent symbol

siunitxtables

I keep getting spurious spaces when I use the siunitx in a tabular environment in the presence of a percent (%) symbol. I am trying to align at the decimal point.

My code is:

\begin{tabular}{lS}
    One   & 0.1234\percent \tabularnewline
    Two   & 1.234\percent  \tabularnewline
    Three & 12.34\percent  \tabularnewline
    Four  & 123.4\percent  \tabularnewline
    Five  & 1234\percent   \tabularnewline
    Six   & 1234.0\percent \tabularnewline
\end{tabular}

and the resulting output is:

Result

The decimal-point alignment is working but the percent symbol has increasing number of spaces as the whole number part of the number increases.

Is there a way of removing these spaces easily, so that the percent symbols appear right after the number? I can hack it by having the percent symbol appear as a unit in a separate column, i.e.

\begin{tabular}{lSs}
    One & 0.1234 & \percent \tabularnewline

but is there a way of having the percent symbol right next to the number as it appears for One, Two and Three above, e.g.

   0.1234%
1234%

Thank you!

Best Answer

The S column is intended for numbers only: it is not the same as using both arguments to \SI. Normally, I would suggest either using two separate columns and remove the inter-column padding uisng @{}:

\documentclass{article}
\usepackage{siunitx}
\begin{document}

\begin{tabular}{lS[table-format=4.4]@{}s}
    One   &    0.1234 & \percent \\
    Two   &    1.234  & \percent \\
    Three &   12.34   & \percent \\
    Four  &  123.4    & \percent \\
    Five  & 1234      & \percent \\
    Six   & 1234.0    & \percent \\
\end{tabular}

\end{document}

or even better adding this information to the header

\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}

\begin{tabular}{lS[table-format=4.4]}
  \toprule
    & {Value/\si{\percent}} \\
  \midrule
    One   &    0.1234 \\
    Two   &    1.234  \\
    Three &   12.34   \\
    Four  &  123.4    \\
    Five  & 1234      \\
    Six   & 1234.0    \\
  \bottomrule
\end{tabular}

\end{document}

If you do want the input as given, you need free-standing-units, alter the definition of \percent and fiddle a bit with the alignment settings

\documentclass{article}
\usepackage{siunitx}
\sisetup{free-standing-units}
\DeclareSIUnit[number-unit-product={}]{\percent}{\%}
\begin{document}

\begin{tabular}{lS[table-format=4.4,table-align-text-post=false]}
    One   &    0.1234\percent \\
    Two   &    1.234 \percent \\
    Three &   12.34  \percent \\
    Four  &  123.4   \percent \\
    Five  & 1234     \percent \\
    Six   & 1234.0   \percent \\
\end{tabular}

\end{document}
Related Question