2

I've just discovered siunitx, which seems to do what I want with tables, that is centering a column but keeping numbers decimal aligned. I find it doesn't work for a column of integers (say 99, 9, 99, 99). The numbers are correctly aligned among themselves, but are not centered correctly within the column, being shifted one or two positions to the left of where they should be. I'm using siunitx with no change of options, and just a plain {S} as the column type. It works fine for columns of numbers with decimal points, but it gets columns of integers wrong.

1

1 Answer 1

7

You can use the table-format option, to specify how much space to set aside for each part of the numbers in the table. If you have integers of up to, say, 3 digits, you can use table-format=3 to set aside space for 3 integer digits, and no decimals.

As stated in the comments, this option can also be set on a per-column basis, by passing the options to the column definition when it is used.

Here's an example:

\documentclass{article}
\usepackage{siunitx}

\begin{document}

\begin{table}
  \sisetup{
    table-format = 2,
  }
  \begin{tabular}{SSS}
    A  & B  & C  \\
    15 &  3 &  2 \\ 
    20 &  2 & 19 \\ 
    25 & 24 &  4 \\ 
  \end{tabular}
\end{table}

\begin{table}
  \begin{tabular}{
      S[table-format=2.3] % with space for integers and decimals
      S[table-format=2]   % with space for integers only
      S                   % as the default
    }
    A  & B  & C  \\
    15 &  3 &  2 \\ 
    20 &  2 & 19 \\ 
    25 & 24 &  4 \\ 
  \end{tabular}
\end{table}

\end{document}

Here's how the aligned integers look:

enter image description here

4
  • 1
    It's probably worth pointing out that you can also specify the table format for each column individually, using S[table-format=2] in the column specification.
    – Jake
    Commented Apr 23, 2015 at 11:04
  • 1
    True. Will add it into the answer.
    – jja
    Commented Apr 23, 2015 at 11:07
  • Thank you. Adding tab;e-format to the S column type does the job. Puzzles me a bit why this is necessary, but this is a very minor query. Having only about a year ago discovered latex and all the associated packages, I think it's great. Whatever you want to do someone seems to have provided the necessary package. How did I ever get by with MSWord! Commented Apr 23, 2015 at 11:27
  • @MikeTanner Glad it worked. If this solved your problem, make sure to mark it as the accepted answer to show that it did.
    – jja
    Commented Apr 23, 2015 at 11:37

You must log in to answer this question.

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