# Format table with aligned values +/- errors and units (and parentheses)

I want to have a table with numbers ± errors and units (or a percent sign). Ideally, the numbers are aligned at the decimal separators and the ± sign. Here is my best solution so far using siunitx that does not have units:

\sisetup{
table-number-alignment=center,
separate-uncertainty=true,
table-figures-integer = 1,
table-figures-decimal = 2}
\begin{table}
\centering
\caption{Fancy caption describing the table}
\label{tab:fancy_table}
\begin{tabular}{l
S[separate-uncertainty,table-figures-uncertainty=1]
S[separate-uncertainty,table-figures-uncertainty=1]
S[separate-uncertainty,table-figures-uncertainty=1]
S[separate-uncertainty,table-figures-uncertainty=1]}
\toprule
& \multicolumn{2}{c}{I} & \multicolumn{2}{c}{II} \\
{Category}    & {a} & {b} & {c} & {d} \\
\midrule
{A}           & 2.51 \pm 0.15   & 2.49 \pm 0.11 & 2.28 \pm 0.05 & 2.23 \pm 0.05 \\
{B}           & 2.51 \pm 0.15   & 4.20 \pm 0.05 & 4.20 \pm 0.05 & 4.20 \pm 0.05 \\
{C}           & 0.22 \pm 0.05   & 4.20 \pm 0.05 & 4.20 \pm 0.05 & 4.20 \pm 0.05 \\
\midrule
{Total}       & 4.20 \pm 0.05   & 4.20 \pm 0.05 & 4.20 \pm 0.05 & 4.20 \pm 0.05 \\
\bottomrule
\end{tabular}
\end{table}


Which produces this table:

So far, so good. Now all these numbers have units. Or, in this example are percentages. The formatting rules I am bound to request to format these values as

(0.22 ± 0.05)%


or

(0.22 ± 0.05) mm


This can be achieved with siunitx:

\sisetup{separate-uncertainty=true}
\SI{100 \pm 12}{\percent}


However, putting both together and adding \SI{x.xx \pm x.xx}{\percent} in the table breaks the alignment.

Can I achieve both, somehow?

The main issue appears to be the placement of the units -- here, percent (%). Since the information about the units of measurement is important and is (hopefully) the same for every entry in a given column, it's convenient to place the information about the units in the table's header. I suggest you place it right above \midrule.

Some minor points: (i) Since the left-hand column has type l, there's no need to encase the cell contents in curly braces. (ii) I added a couple of \cmidrule lines to make it entirely clear that "I" goes with "a" and "b" while "II" goes with "c" and "d".

\documentclass{article}
\usepackage{siunitx,booktabs}
\sisetup{ table-number-alignment=center,
separate-uncertainty=true,
table-figures-integer = 1,
table-figures-decimal = 2}
\begin{document}
\begin{table}
\caption{Fancy caption describing the table}
\label{tab:fancy_table}
\sisetup{table-figures-uncertainty=1}
\centering
\begin{tabular}{@{} l *{4}{S} @{}}
\toprule
Category & \multicolumn{2}{c}{I} & \multicolumn{2}{c@{}}{II} \\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& {a} & {b} & {c} & {d} \\
& {(\%)} & {(\%)} & {(\%)} & {(\%)}  \\
\midrule
A  & 2.51 \pm 0.15   & 2.49 \pm 0.11 & 2.28 \pm 0.05 & 2.23 \pm 0.05 \\
B  & 2.51 \pm 0.15   & 4.20 \pm 0.05 & 4.20 \pm 0.05 & 4.20 \pm 0.05 \\
C  & 0.22 \pm 0.05   & 4.20 \pm 0.05 & 4.20 \pm 0.05 & 4.20 \pm 0.05 \\[1ex]
Total & 4.20 \pm 0.05   & 4.20 \pm 0.05 & 4.20 \pm 0.05 & 4.20 \pm 0.05 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

• Would be my answer, but from the way the question reads I have a feeling each value has to be given with a unit (bad but ...) – Joseph Wright Sep 8 '14 at 18:41
• I would sincerely hope that units are common for all entries in a given column. However, as you point out, this may not actually be the case. Let's hear from the OP which case applies. – Mico Sep 8 '14 at 18:47
• Thanks for this solution and the annotations. In this case it is perfectly acceptable for my needs. However, not always do all numbers have the same unit (for example one could use a table to summarize various parameters describing a model having different units). – Florian Kruse Sep 10 '14 at 9:26
• @FlorianKruse - If the units are by shared by all entries in a given row, I'd be tempted to place that information in the cell in the left-most column (the one that describes the parameter). If you have a table where units can differ across both rows and columns, you should assume that your readers are going to have a hard time figuring out what's going on and, as a result, aren't likely to bother understanding its contents. To abate this risk, you may want to think about how to simplify the table's structure. – Mico Sep 10 '14 at 9:41