# siunitx | Alignments in Table

Consider the following (refined) MWE:

\documentclass{article}
\usepackage[locale=DE]{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\caption{S{\o}vnm{\ae}ngde blandt elever i niende klasse.}
\label{tbl:2}
\begin{tabular}{
S[table-format = 1.1]
S[table-format = 2.0]
S[table-format = 2.0]<{{\,\si{\percent}}}
S[table-format = 2.0]
S[table-format = 2.0]<{{\,\si{\percent}}}
}
\toprule
{Antal timer} &
\multicolumn{2}{c}{Andel af eleverne fra 9.~A} &
\multicolumn{2}{c}{Andel af eleverne fra 9.~B}   \\
\midrule
& {Abs.} & \multicolumn{1}{c}{Rel.} & {Abs.} & \multicolumn{1}{c}{Rel.} \\
\midrule
6.5 &  1     &   4    &   0    &   0 \cr
7   &  4     &  16    &   2    &  10 \cr
7.5 & 99     &  12    &   3    &  15 \cr
\bottomrule
\end{tabular}
\end{table}

\end{document}


I try to put three columns (instead of two), i.e. also one with integers, under each of ''Something random B'' and ''Something random C''. (I need both absolute and relative values under ''Something random B'' and ''Something random C''.)

How do I do this?

@Joseph Wright: An trivial extension of your code is not obvious to me.

P.S. Sorry for not asking the right question the first time.

Update: I have modified the code. Now it compiles fine, but the columns with ''Abs.'' numbers and ''Rel.'' numbers+units are not centered properly under ''Andel af eleverne fra 9. A'' and ''Andel af eleverne fra 9. B'', resp.

Also, the numbers and numbers+units seem not to be directly under ''Abs.'' and ''Rel.'', resp.

How do I fix this?

Update 2: Clemens Niederberger helped me with a solution at the LaTeX Community, here.

-
Are your units always the same (as in the example)? – Joseph Wright Sep 20 '12 at 11:43
Isn't the usual recommendation that if the unit is common thoughout a column, then the unit is listed in the column header, and not repeated in the column – daleif Sep 20 '12 at 12:19
@Joseph Wright: Yes – Svend Tveskæg Sep 20 '12 at 12:31
@daleif: I think so, but I would like to have the percentage symbol next to the numbers. – Svend Tveskæg Sep 20 '12 at 12:32

As mentioned in the comment, you would usually divide through in this case so that none of the values need a unit. However, if you want the unit then

\documentclass{article}
\usepackage[locale=DE]{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\begin{tabular}{
S[table-format = 1.1]
S[table-format = 2.3]<{{\,\si{\percent}}}
S[table-format = 2.3]<{{\,\si{\percent}}}
}
\toprule
{Something random~A} &
\multicolumn{1}{c}{Something random~B} &
\multicolumn{1}{c}{Something random~C}  \\
\midrule
6.5 &  2.35  &  2.35  \cr
7   & 34.234 & 34.234 \cr
7.5 &  3.762 &  3.762 \cr
\bottomrule
\end{tabular}
\end{table}

\end{document}


should work. Note the requirement to use \cr not \\ for this (see 'Adding items after the last column of a tabular' in the siunitx manual).

-
Perfect. I have actually come to the conclusion that I need another two columns of numbers (without units) next to the numbers with units; one column under each of ''Something random B'' and ''Something random C''. (I have answered my own question with an extension of the original code, but now it will not even compile.) – Svend Tveskæg Sep 20 '12 at 14:14