12

In this table with some big numbers the column headers centered over the decimal point look odd to me. And, too, the columns seem a little too wide.

enter image description here

I've puttered a bit with other answers here and package documentation to little effect. Maybe I haven't looked hard enough - so am asking for help.

Here's the MWE:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{input-ignore={,},input-decimal-markers={.},group-separator={,}}

\begin{document}
\begin{tabular}{lSSS}
\toprule
          &            &            & \multicolumn{1}{c}{Natural} \\
Time unit & \multicolumn{1}{c}{Births} & \multicolumn{1}{c}{Deaths} & \multicolumn{1}{c}{increase} \\ 
\midrule
Year  &    134,176,254 &   56,605,700 &    77,570,553 \\
Month &     11,181,355 &    4,717,142 &    6,464,213 \\
Day   &        367,606 &      155,084 &       212,522 \\
Minute&            255 &          108 &           148 \\
Second&            4.3 &          1.8 &           2.5 \\
\bottomrule
\end{tabular}
\end{document}

1 Answer 1

14

You need to tell siunitx how many digits are to the left and right of the decimal separator (alignment point). The key table-format does the trick.

Note also that here, a brace group is sufficient to escape the header text. The \multicolumn solution is only required in special cases.

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{input-ignore={,},input-decimal-markers={.},group-separator={,}}

\begin{document}
\begin{tabular}{lS[table-format=9.1]*2{S[table-format=8.1]}}
\toprule
          &             &            & {Natural}  \\
Time unit & {Births}    & {Deaths}   & {increase} \\
\midrule
Year      & 134,176,254 & 56,605,700 & 77,570,553 \\
Month     &  11,181,355 &  4,717,142 &  6,464,213 \\
Day       &     367,606 &    155,084 &    212,522 \\
Minute    &         255 &        108 &        148 \\
Second    &         4.3 &        1.8 &        2.5 \\
\bottomrule
\end{tabular}
\end{document}

The setting table-format=9.1 indicates that there are 9 digits before the alignment point and 1 digit after it. Similar for the other columns. I've also used *<num>{<col-spec>} notation for repeated common columns to reduce repetition.

enter image description here

2
  • 5
    Just {...} is sufficient instead of \multicolumn{1}{c}{...} in the headers.
    – egreg
    Apr 14, 2015 at 13:39
  • @egreg improvements in progress... :-) Apr 14, 2015 at 13:40

You must log in to answer this question.

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