Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
    
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 '12 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 '12 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 '12 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 '12 at 11:50
add comment

1 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}
share|improve this answer
1  
I'm assuming siunitx version 2.x: update the question if a version 1.x answer is needed! –  Joseph Wright Jul 18 '12 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 '12 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 '12 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 '12 at 13:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.