2

I'm doing some tables but I can't find the right alignment using siunitx. I believe that the first and last column numbers should be more to the left and the second column numbers more to the right. I can't find a way to adjust this.

Here is a minimum working example:

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{table}[ht]
\centering
\begin{tabular}{SSS}
\toprule
{Coefficient} & {Iterations} & {Spectral condition}\\\midrule
1e0 & 112 & 2e3 \\
1e-2 & 768 & 1.7e4 \\
1e-4 & 2961 & 3.8e5 \\
1e-6 & 7760 & 3.7e7 \\
\bottomrule
\end{tabular}
\caption{First experiment.}
\label{tab:firstexperiment}
\end{table}%

\end{document}

It looks like the first table, but I want it to look like the table below.

  • 1
    Your column heads (in S columns) should simply be between braces – \text should be removed. – Bernard Oct 7 '18 at 23:53
  • Thanks, I fixed it. It doesn't change alignment. – Migue Oct 7 '18 at 23:59
2

Centring heads in S columns depends on the format of the numbers in the column, so I specified the format in each column. Does this code produce what you want?

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}


\begin{table}[!htb]
\centering\sisetup{table-number-alignment=center}
\begin{tabular}{S[table-format=1e-1]S[table-format=4.0]S[table-format=1.1e1]}
\toprule
{Coefficient} & {Iterations} & {Spectral condition}\\\midrule
1e0 & 112 & 2e3 \\
1e-2 & 768 & 1.7e4 \\
1e-4 & 2961 & 3.8e5 \\
1e-6 & 7760 & 3.7e7 \\
\bottomrule
\end{tabular}
\caption{First experiment.}
\label{tab:firstexperiment}
\end{table}%

\end{document} 

enter image description here

2

Welcome to TeX.SE! It is not too surprising that the alignment is not what you want since you are using the S column also for the headers. There are certainly more advanced options (there seems to be an almost infinite number of options when it comes to design tables, the pgfmanual is short in comparison), but to very first approximation I'd do

\documentclass{article}

\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{table}[ht]
\centering
\begin{tabular}{SSS}
\toprule
\multicolumn{1}{r}{Coefficient} & \multicolumn{1}{l}{Iterations} & \multicolumn{1}{r}{Spectral condition}\\
\midrule
1e0 & 112 & 2e3 \\
1e-2 & 768 & 1.7e4 \\
1e-4 & 2961 & 3.8e5 \\
1e-6 & 7760 & 3.7e7 \\
\bottomrule
\end{tabular}
\caption{First experiment.}
\label{tab:firstexperiment}
\end{table}%
\end{document}

enter image description here

  • Thanks, the first column looks better. But sadly multicolumn doesn't seem to fix the second and third column alignment. – Migue Oct 7 '18 at 23:41
  • 2
    @Migue Without a crystal ball it is impossible to guess what you want. If you make a details description of what you want to achieve I will have a look at it (but only in a few hours, will be leaving know). – user121799 Oct 7 '18 at 23:47
  • I added an image that might clarify things. – Migue Oct 8 '18 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.