4

I've searched around this site and also a lot with Google, but did not find exactly a solution to my problem.

I want to create a table width equally (and automatically) spaced columns. These columns contain numerical values, which should be aligned at the decimal marker. In each column, the whole number block shall then be centered with respect to the column.

I've tried using S columns of the siunitx package with the table-number-alignment=center option and fideling around with table-format=n.m. However, this only works, if in all columns there occurs at least once a number having +n integers or m decimal places. Here a short example of my efforts, the vertical line are only for visualization:

\documentclass{article}

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{siunitx}
\begin{document}

\begin{table}\small
  \centering
  \sisetup{
  table-number-alignment = center,
  table-format=+2.3
  }
  \begin{tabularx}{\textwidth}{
  @{}c|*{7}{S|}@{}
  }
  \toprule
    Text & aa & bb  & cc &  ff &  gg  &   hh   &   kk    \\
  \midrule
    Text & 1    &  0.115 &  0.086 & 1.41  &  0.23  &  0.092 &  6.82    \\
    Text & -32  &  5.3   & -36    & 0.01  &  50.1  &  0.7   & -18.8   \\
  \bottomrule
  \end{tabularx}
  \caption{Example}
\end{table}
\end{document}

Column cc looks as it should, because it matches the +2.3 figure-format, while columns bb or hh look somewhat strange. I want these numbers to be centered, too. Is it possible to get the desired look using the siunitx package?

2

3 Answers 3

2

Automatic setting of table-format is not currently possible. To set up to maintain alignment, it is necessary to know how much space to reserve. This depends on all of the entries in a column, not just the current entry. Thus to set table-format automatically would require some significant change to the entire way that tables are constructed. As the S column is intended to be used with a range of LaTeX tabular-like implementations, this is not really desirable. Thus you do have to set the format on a per-column basis.

1

Building upon Joseph's answer, here's a way to fill the line width with the table:

\documentclass{article}

\usepackage{booktabs}
\usepackage{widetable}
\usepackage{siunitx}
\begin{document}

\begin{table}\small
  \centering
  \sisetup{table-number-alignment = center}
  \begin{widetable}{\textwidth}{
  c
  S[table-format=+2.0]
  S[table-format=1.3]
  S[table-format=+2.4]
  S[table-format=1.2]
  S[table-format=2.2]
  S[table-format=1.3]
  S[table-format=+2.2]
  }
  \toprule
    Text & aa & bb  & cc &  ff &  gg  &   hh   &   kk    \\
  \midrule
    Text & 1    &  0.115 &  0.086 & 1.41  &  0.23  &  0.092 &  6.82    \\
    Text & -32  &  5.3   & -36    & 0.01  &  50.1  &  0.7   & -18.8   \\
  \bottomrule
  \end{widetable}
  \caption{Example}
\end{table}
\end{document}

The widetable package overcomes some problems of the tabular* environment. I didn't think it worked with S columns, I was wrong. The widetable environment works similarly to tabular*, adding to the intercolumn space, which is what is needed here.

0

Inspired by the answer of @egreg I came up with a solution myself. Before posting the code, I should perhaps clarify that the point, which was important to me in my original problem, was the equal width of the siunitx columns. Unfortunately I wrote "equally spaced column" instead of something "columns with equal width".

The widetable package solution does not provide equal width columns. I used the tabu package instead, as this appraently allows to embedd S columns in the tabu X column. As @Joseph pointed out the format must set on per-column-basis.

\documentclass{article}

\usepackage{booktabs}
\usepackage{tabu}
\usepackage{siunitx}
\begin{document}

\begin{table}\footnotesize
 \centering
 \sisetup{table-number-alignment = center}
 \begin{tabu} to \textwidth {
 c|
 X[c]{S[table-format=+2]}|
 X[c]{S[table-format=1.3]}|
 X[c]{S[table-format=+2.3]}|
 X[c]{S[table-format=1.2]}|
 X[c]{S[table-format=2.2]}|
 X[c]{S[table-format=1.3]}|
 X[c]{S[table-format=+2.2]}|
 }
 \toprule
   Text & aa & bb  & cc &  ff &  gg  &   hh   &   kk    \\
 \midrule
   Text & 1    &  0.115 &  0.086 & 1.41  &  0.23  &  0.092 &  6.82    \\
   Text & -32  &  5.3   & -36    & 0.01  &  50.1  &  0.7   & -18.8   \\
 \bottomrule
 \end{tabu}
 \caption{Example}
\end{table}

\end{document}

You must log in to answer this question.

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