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.

OK, what am I missing here? Why is the S column not aligning on the decimal:

enter image description here

The desired result is the data aligned on the decimal and centered within the column:

enter image description here

Code:

\documentclass{article}
\usepackage{siunitx}

\begin{document}
    \begin{tabular}{S}
    \multicolumn{1}{c}{Measured Values} \\
        \SI{0.003 1}{\meter} \\
        \SI{0.003 123}{\meter} \\
        \SI{0.003 45}{\meter} \\
    \end{tabular} 
\end{document}
share|improve this question

2 Answers 2

The S column type is meant to take inputs in the same format as the single mandatory argument to siunitx's \num{} command. Anything else is interpreted as text (for headings, etc.) and is centered about the decimal point location.

This is why you see the overall centering behavior: The \SI{}{} is interpreted as something that is "not a number" and is formatted as header text or other material.

To typeset the units, use an s column, which takes inputs in the same form as the mandatory argument to the \si{} command. This should only be used if the units are not the same for every row in the table.

Example:

\documentclass{article}
\usepackage{siunitx}

\begin{document}
    \begin{tabular}{S[table-format=1.6]s}
    \multicolumn{2}{c}{Measured Values} \\
        0.0031   & \meter \\
        0.003123 & \meter \\
        0.00345  & \meter \\
    \end{tabular} 
\end{document}

enter image description here

If the units of a particular column are the same for every row (as is the case for most tables), use the recommendation of Section 9.3 of the siunitx manual; that is, represent the numbers using dimensionless ratios:

\documentclass{article}
\usepackage{siunitx}

\begin{document}
    \begin{tabular}{S[table-format=1.6]}
    {Measured Values/\si{\meter}} \\
        0.0031   \\
        0.003123 \\
        0.00345  \\
    \end{tabular} 
\end{document}

enter image description here

Or (my preference):

\documentclass{article}
\usepackage{siunitx}

\begin{document}
    \begin{tabular}{S[table-format=1.6]}
    {Measured Values (\si{\meter})} \\
        0.0031   \\
        0.003123 \\
        0.00345  \\
    \end{tabular} 
\end{document}

enter image description here

Notice how table-format=1.6 is used to specify the maximum number of integer and decimal digits in each column entry. This allows for proper centering of the data. Also, I used curly braces around the heading to "protect" it and mark it as non-numerical data. This is not required here, because siunitx is pretty smart about detecting these cases. The curly brace protection is useful in certain cases where siunitx gets confused (integer index headings, for example).

share|improve this answer
    
Hmmm, I just I just assumed that the S column type from the siunitx package would know about the \SI{}{} macro form the \siunitx package. :-) –  Peter Grill Aug 13 at 0:28
1  
@PeterGrill Well \SI wouldn't make sense in any case: it's a quantity not a number, so what the logical outcome of 'align in a numerical column' is is undefined. –  Joseph Wright Aug 13 at 7:18

In case if you have to use different units for different numbers, you have these possibilities with table-space-text-post and table-align-text-post:

\documentclass{article}
\usepackage{siunitx}

\begin{document}
    \begin{tabular}{S[table-format=1.6,table-space-text-post = \si{\meter}]}
    {Measured Values} \\
        0.0031\si{\meter}   \\
        0.003123\si{\meter} \\
        0.00345\si{\meter}  \\
    \end{tabular}
    \begin{tabular}{S[table-format=1.7,table-align-text-post = false]}  %% note 1.7 here just to align things at center
    {Measured Values} \\
        0.0031\,\si{\meter}   \\
        0.003123\,\si{\meter} \\
        0.00345\,\si{\meter}  \\
    \end{tabular}
\end{document}

enter image description here

There is also pre version of above commands - table-align-text-pre which does the same before the number.

share|improve this answer
    
Very nice; I didn't know about these keys until reading your answer. Is it possible to add a thin space to obtain the proper spacing at the widest number? I tried table-space-text-post = {\,\si{\meter}} but the result did not change. –  Paul Gessler Aug 13 at 0:27
    
I think you should add a \, before the unit to get the same spacing (as the \SI{}{}) macro would produce) - especially in the second example. –  Peter Grill Aug 13 at 0:27
2  
@PaulGessler: I agree, but it may be an extra work for Joseph :) –  Harish Kumar Aug 13 at 0:35
1  
@PaulGessler If you want something to appear in every row, the array >{...} mechanism is the way to go. (I'd strongly prefer dividing through as you've said in your answer, otherwise there is repeated information for no reason.) –  Joseph Wright Aug 13 at 6:09
1  
@HarishKumar BTW, you'd be better with \,\si{\metre} as this way the unit is in 'interpreted' mode (would make a difference if the unit was e.g. \per\metre). –  Joseph Wright Aug 13 at 6:10

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.