2

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!

4
  • Welcome to TeX.SE! What you call a spurious space is actually a conscious design decision; see p. 81 of the user guide of the siunitx package.
    – Mico
    Jul 18, 2012 at 11:41
  • Or perhaps it is the problem stated in page 45 of siunitx documentation? (btw, my siunitx guide has only 60 pages)
    – JLDiaz
    Jul 18, 2012 at 11:45
  • I forgot to add: If you must have a percent symbol without any space between the numbers and the symbols, (a) use the \% control sequence instead of \percent and (b) issue the command \sisetup{input-symbols=\%} ahead of the table in question.
    – Mico
    Jul 18, 2012 at 11:49
  • @JLDiaz: Which version of siunitx is installed on your system? (The one on my system is numbered 2.5e.)
    – Mico
    Jul 18, 2012 at 11:50

1 Answer 1

6

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}
4
  • 1
    I'm assuming siunitx version 2.x: update the question if a version 1.x answer is needed!
    – Joseph Wright
    Jul 18, 2012 at 11:52
  • Thank you all. I have version 1.x at the moment so I am updating to the latest siunitx, and will then attempt the above fix/es. If that fails, then I might ask for version 1.x fix.
    – salestial
    Jul 18, 2012 at 12:31
  • @salestial If you are getting siunitx v2 from CTAN, you must also get the latest l3kernel and l3packages. They have to 'match' and were all updated 48 h ago!
    – Joseph Wright
    Jul 18, 2012 at 12:35
  • It works! It was indeed a version problem - version 1.3 was not even supporting (or was throwing an error) keyword arguments to S. All sorted now though - thanks all!
    – salestial
    Jul 18, 2012 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .