8

I would like to format the following table with siunitx package:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{table}
\centering
\begin{tabular}{S[table-format=3.0]ccc} \\
\toprule
$n$ & A & $\alpha_0$ & $\beta_0$ \\
\midrule
100 & ML & 3.1525(0.3580) & 0.4773(0.1209) \\
200 & YW & 3.1866(0.3272) & 0.4593(0.1075) \\
300 & ML & 3.1540(0.2660) & 0.4834(0.0858) \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

The critical are 3rd and 4th column which are in the format X.XXXX(Y.YYYY). Any suggestion how to properly format the columns?

3
  • 1
    Please, make cleare what you want to achieve. I mean, what do you want from your formatting? The numbers should appears aligned wrt the decimal separator?
    – gvgramazio
    Commented May 6, 2018 at 13:24
  • @giusva Exactly, the numbers need to appear aligned to the decimal separator.
    – Andrej
    Commented May 6, 2018 at 13:28
  • Look at the answer: maybe is what you're looking for, maybe not.
    – gvgramazio
    Commented May 6, 2018 at 13:40

2 Answers 2

7

In my case they already are. So can you please post another example when your code fails?

Just to be a little helpful I modified your code in order to have number with uncertainty in the 3rd and 4th column. I don't know what you have in the 2nd column, if they are si unit you can also explicit that.

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}
\centering
\begin{tabular}{S[table-format=3.0]cS[table-format=1.4(5)]S[table-format=1.4(5)]} \\
\toprule
{$n$} & A & {$\alpha_0$} & {$\beta_0$} \\
\midrule
100 & ML & 3.1525 \pm 0.3580 & 0.4773 \pm 0.1209 \\
200 & YW & 3.1866 \pm 0.3272 & 0.4593 \pm 0.1075 \\
300 & ML & 3.1540 \pm 0.2660 & 0.4834 \pm 0.0858 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

example_default

You could modify the way the uncertainty is displayed if you want. Personally I don't like the default style but I don't know your tastes.

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{separate-uncertainty = true}

\begin{document}
\begin{table}
\centering
\begin{tabular}{S[table-format=3.0]cS[table-format=1.4(5)]S[table-format=1.4(5)]} \\
\toprule
{$n$} & A & {$\alpha_0$} & {$\beta_0$} \\
\midrule
100 & ML & 3.1525 \pm 0.3580 & 0.4773 \pm 0.1209 \\
200 & YW & 3.1866 \pm 0.3272 & 0.4593 \pm 0.1075 \\
300 & ML & 3.1540 \pm 0.2660 & 0.4834 \pm 0.0858 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

example_separate_unc

4
7

an alternative, exploited are all siunitx features:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}[htb]   % standard record of uncertainty
\centering
\begin{tabular}{S[table-format=3.0]
                c
           *{2}{S[table-format=1.4(4)]}
                }
\toprule
{$n$} & A & {$\alpha_0$} & {$\beta_0$} \\
\midrule
100 & ML & 3.1525(3580) & 0.4773(1209) \\
200 & YW & 3.1866(3272) & 0.4593(1075) \\
300 & ML & 3.1540(2660) & 0.4834(0858) \\
\bottomrule
\end{tabular}
\end{table}

\begin{table}[htb]   % separate record of uncertainty
\sisetup{separate-uncertainty} % <---
\centering
\begin{tabular}{S[table-format=3.0]
                c
           *{2}{S[table-format=1.4(4)]}
                }
\toprule
{$n$} & A & {$\alpha_0$} & {$\beta_0$} \\
\midrule
100 & ML & 3.1525(3580) & 0.4773(1209) \\
200 & YW & 3.1866(3272) & 0.4593(1075) \\
300 & ML & 3.1540(2660) & 0.4834(0858) \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

You must log in to answer this question.

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