3

I am using the siunitx package, along with the booktabs package, to make a table.

Here is my output:

output

Table (a) uses the tabular specification llll (i.e., no use of siunitx). Table (a) looks great, except that I want the decimal points in +0.2 and -0.4 to be lined up.

To do that, in Table (b), I used the tabular specification lSSS and used \sisetup{table-number-alignment=left}. Now the decimal points are aligned, but I would like the numbers in the last two columns to be fully left aligned (flush with the k_{\theta}'s), since they are all positive. How can I do this?

Here is my code:

\documentclass{article}
\usepackage{siunitx,booktabs,subcaption}
\DeclareSIUnit{\calorie}{cal}

\begin{document}

\begin{table}

  \begin{subtable}{\textwidth}
    \caption{}
    \begin{tabular}{llll}
      \toprule
      & {$q$ (\si{\elementarycharge})} & {$k_{\theta}$ (\si{\kilo\calorie\per\mole})} & {$k_{\theta}$ (\si{\kilo\joule\per\mole})}\\
      \midrule
      compound A & +0.2 & 0.066 & 0.276144\\
      compound B & -0.4 & 0.14 & 0.585760\\
      \bottomrule
    \end{tabular}
  \end{subtable}

  \vspace*{16pt}

  \begin{subtable}{\textwidth}
    \caption{}
    \sisetup{table-number-alignment=left}
    \begin{tabular}{lSSS}
      \toprule
      & {$q$ (\si{\elementarycharge})} & {$k_{\theta}$ (\si{\kilo\calorie\per\mole})} & {$k_{\theta}$ (\si{\kilo\joule\per\mole})}\\
      \midrule
      compound A & +0.2 & 0.066 & 0.276144\\
      compound B & -0.4 & 0.14 & 0.585760\\
      \bottomrule
    \end{tabular}
  \end{subtable}

\end{table}

\end{document}

2 Answers 2

5

With the help of table-number-alignment in combination with the appropriate table-format, you can achieve the following output:

enter image description here

\documentclass{article}
\usepackage{siunitx,booktabs}
\DeclareSIUnit{\calorie}{cal}

\begin{document}

\begin{table}
    \begin{tabular}{l
                    S[table-format=-1.1,table-number-alignment=left]
                    S[table-format=1.3,table-number-alignment=left]
                    S[table-format=1.6,table-number-alignment=left]}
      \toprule
      & {$q$ (\si{\elementarycharge})} & {$k_{\theta}$ (\si{\kilo\calorie\per\mole})} & {$k_{\theta}$ (\si{\kilo\joule\per\mole})}\\
      \midrule
      compound A & +0.2 & 0.066 & 0.276144\\
      compound B & -0.4 & 0.14 & 0.585760\\
      \bottomrule
    \end{tabular}

\end{table}

\end{document}
3
  • 1
    +1, however, I wonder, why I cant repeat result, if I move common option table-number-alignment=left in \sisetup for example after \begin{table} or into preamble? In this case the numbers are centered in column :-(
    – Zarko
    Oct 20, 2020 at 22:16
  • Even more interesting is, that the following specifications of table format wirks: \begin{table} \sisetup{table-format= 1.6,table-number-alignment=left} \begin{tabular}{l S[table-format=-1.1] S S}. Is this a bug?
    – Zarko
    Oct 20, 2020 at 22:24
  • @Zarko: moving table-number-alignment=left into a \sisetup does not work since the use of \table-format overwrites the table-number-alignment to its default centered alignment, thus I had so specify the alignment for each column individually. (See also p.48 of the siunitx documentation.) Regarding your second comment: This suggestion only seems to work since column header and entries are almost equally wide, thus left aligned and centered almost look identical. If you add some caracters to the column header, you can see that this header is in fact again horizontally centered.
    – leandriis
    Oct 21, 2020 at 5:51
2

You need to specify the format of numbers in each column; the simple S specification applies a default that's not suitable for your case.

On the other hand, the fact that the numbers are positive doesn't seem to have something to do with alignment.

I'd split the header into two rows, one for the symbols and one for the units.

\documentclass{article}
\usepackage{siunitx,booktabs}
\DeclareSIUnit{\calorie}{cal}

\begin{document}

\begin{table}
\centering

\begin{tabular}{
 @{}
 l
 S[table-format=-1.1,retain-explicit-plus,table-number-alignment=left]
 S[table-format=1.3,table-number-alignment=left]
 S[table-format=1.6,table-number-alignment=left]
 @{}
}
\toprule
& {$q$ (\si{\elementarycharge})}
& {$k_{\theta}$ (\si{\kilo\calorie\per\mole})}
& {$k_{\theta}$ (\si{\kilo\joule\per\mole})} \\
\midrule
compound A & +0.2 & 0.066 & 0.276144\\
compound B & -0.4 & 0.14 & 0.585760\\
\bottomrule
\end{tabular}

\bigskip

\begin{tabular}{
 @{}
 l
 S[table-format=-1.1,retain-explicit-plus]
 S[table-format=1.3]
 S[table-format=1.6]
 @{}
}
\toprule
& {$q$}
& {$k_{\theta}$}
& {$k_{\theta}$} \\
& {(\si{\elementarycharge})}
& {(\si{\kilo\calorie\per\mole})}
& {(\si{\kilo\joule\per\mole})} \\
\midrule
compound A & +0.2 & 0.066 & 0.276144\\
compound B & -0.4 & 0.14 & 0.585760\\
\bottomrule
\end{tabular}

\end{table}

\end{document}

enter image description here

In the second sample, the big white space has disappeared.

You must log in to answer this question.

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