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.

Consider the following MWE:

\documentclass{article}

\usepackage{siunitx}

\begin{document}
  \begin{tabular}{SS}
        0.01    & \num{0.01} \\
        0.1     & \num{0.1} \\
        1       & \num{1} \\
        10      & \num{10} \\
        100     & \num{100} \\
  \end{tabular}
\end{document}

Which gives:
enter image description here

Why does the left column display as desired, and the right not?

Secondly, I would like to add a range of numbers of the table.

\documentclass{article}

\usepackage{siunitx}

\begin{document}
  \begin{tabular}{rS}
        0.01        & \num{0.01} \\
        0.1         & \num{0.1} \\
        1           & \num{1} \\
        10          & \num{10} \\
        100         & \num{100} \\
        101--1000   & \numrange{101}{1000}
  \end{tabular}
\end{document}

enter image description here

How would I do that typographically "correct"?

share|improve this question
    
I've edited the answer to remove the use of LuaTeX-specific packages, which are not needed for the demo. –  Joseph Wright Nov 23 '11 at 16:18

1 Answer 1

up vote 5 down vote accepted

On the first part of the question, the S column aligns numbers, and treats any other input as 'non-numerical'. So when parsing your second column, the \num macro is a 'non-numerical' value, and the cell content is typeset omitted from alignment. Simply don't use \num to indicate numbers within an S column.

On the second part of the question, ranges intermixed with decimal values are hard to align nicely: to be honest, such a table tends to suggest that there is something wrong with what you are attempting to present. That said, something like

\documentclass{article}

\usepackage{siunitx}

\begin{document}
  \begin{tabular}{S[table-format = 3.2,table-align-text-post = false]}
        0.01        \\
        0.1         \\
        1           \\
        10          \\
        100         \\
        101{--1000} \\
  \end{tabular}
\end{document}

will work in the case give. The idea here is to ignore the second part of the range for alignment purposes. I've also given a fixed size to the number as a whole, as this gives better alignment in general.

share|improve this answer
    
Wouldn't {101--1000} be a better choice in the last row? I.e. center it instead of aligning? Then the column will not be too tail heavy –  daleif Nov 23 '11 at 16:51
    
@daleif It depends on the 'real' case (for example, how many ranges). I guess you should post this as an alternative answer (or I can edit it into mine). –  Joseph Wright Nov 23 '11 at 16:53
    
That answer couldn't come more first hand. Thanks! –  Ingo Nov 24 '11 at 11:22

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.