# How to combine cmidrule of the booktabs-package with siunitx correctly?

After rewriting this post multiple times, I'll just write it like this:

• How can I use \cmidrule in combination with siunitx? Is this even adviseable or not?

• Did I make an error somewhere else? The whole table looks so. freaking. weird.

I like the way the error (values are actually the confidence intervals but never mind) are parsed. But overall the rules put below AAA, BBB and CCC, I just do not get them. I also do not understand why the cmidrule below AAA goes way too far to the left? I'd really like to avoid the weird rule lengths and just have it as long as the vanilla command would produce it. :(

## MWE

\documentclass[
a4paper
]{scrartcl}

\usepackage{
lmodern,
booktabs
}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[
per-mode=fraction,
locale=DE,
separate-uncertainty=true,
retain-explicit-plus,
binary-units,
%table-number-alignment=right
]{siunitx}

\begin{document}
\begin{tabular}{lSSSS}
\toprule
{ValueA} & {VALUEb} & {AAA} & {BBB} & {CCC} \\
\cmidrule(lr){1-1}
\cmidrule(lr){2-2}
\cmidrule(lr){3-3}
\cmidrule(lr){4-4}
\cmidrule(lr){5-5}
20 & 10 & -95,57(7) & 75,18 & -45,88 \\
& 20 & -142,72(12) & 89,20 & -58,62 \\
& 30 & -161,83(16) & -1118,51 & -75,19 \\
\bottomrule
\end{tabular}
\end{document}

• by default I think it's centering on the decimal point, that's what it looks like from your image, the S column has assorted options to specify alignment though so you can change that Oct 6, 2014 at 19:15
• @DavidCarlisle Edited op. Oct 6, 2014 at 19:19

Incorporating the minus signs in table-format=… and choosing table-number-alignment=center (the default is center-decimal-marker) will give an acceptable result, in my opinion:

\documentclass[a4paper]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern,booktabs}

\usepackage[per-mode=fraction, locale=DE, separate-uncertainty=true, retain-explicit-plus, binary-units, table-number-alignment=center, ]{siunitx}

\begin{document}

\begin{tabular}{lcS[table-format=-3.2(2)]S[table-format=-4.2]S[table-format=-2.2]}%
\toprule
{ValueA} & {ValueB} & {AAA} & {BBB} & {CCC} \\
\cmidrule(lr){1-1}
\cmidrule(lr){2-2}
\cmidrule(lr){3-3}
\cmidrule(lr){4-4}
\cmidrule(lr){5-5}
20 & 10 & -95,57(7) & 75,18 & -45,88 \\
& 20 & -142,72(12) & 89,20 & -58,62 \\
& 30 & -161,83(16) & -1118,51 & -75,19 \\
\bottomrule
\end{tabular}

\end{document}


• Oops! Completely overlooked that point. I'll update my answer at once. Oct 6, 2014 at 21:24

An S column needs refinements, the most common one is specifying the format of the numbers it contains; otherwise it does just some heuristics that usually don't work well.

\documentclass[
a4paper
]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{
lmodern,
booktabs,
}

\usepackage[
per-mode=fraction,
locale=DE,
separate-uncertainty=true,
retain-explicit-plus,
binary-units,
%table-number-alignment=right,
]{siunitx}

\begin{document}

\begin{tabular}{
l
S[table-format=2.0]
S[table-format=-3.2(2)]
S[table-format=-4.2]
S[table-format=-2.2]
}
\toprule
{ValueA} & {VALUEb} & {AAA} & {BBB} & {CCC} \\
\cmidrule(lr){1-1}
\cmidrule(lr){2-2}
\cmidrule(lr){3-3}
\cmidrule(lr){4-4}
\cmidrule(lr){5-5}
20 & 10 &   -95,57(7) &    75,18 & -45,88 \\
& 20 & -142,72(12) &    89,20 & -58,62 \\
& 30 & -161,83(16) & -1118,51 & -75,19 \\
\bottomrule
\end{tabular}

\end{document}


Note the uncertainty in column 3. If you don't specify it, the uncertainty will not be displayed.

Use S for the preliminary version and fine tune it when you know the data are definitive.

• Giving Bernard the checkmark because he was 2 minutes faster. Besides, he really seems to need it with his mere \approx 22k magic points against your 320k. ;) Oct 6, 2014 at 20:22
• @henry No problem for me; but I wanted to point out the uncertainty bit. Oct 6, 2014 at 20:25
• Noted that it is no problem and that you did not engage my joke. :( Also now I understand the little difference between your reply and Bernard's which actually makes you rreply better. And I would feel bad to take the magic points away from him and add them to your 320k. Oct 6, 2014 at 20:31
• @henry So feel good and leave them to him. ;-) Oct 6, 2014 at 20:33
• It just dawned on me that (in regards to the first uncertainty value) the value (7) is interpreted as 0.07. Or 7 percent, which is equally wrong for my data. Also I get an error when writing table-format=4.2(2.2) and supplying the data accordingly. Can I not do that? Oct 7, 2014 at 7:15