Sunday, 25 August 2013

Horizontal centering in table

Horizontal centering in table

Consider the following example:
\documentclass{article}
\usepackage{booktabs,dcolumn}
\usepackage{siunitx}
\newcolumntype{d}[1]{D{.}{,}{#1}}
\newcommand*\mc[1]{\multicolumn{1}{c}{#1}}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Something.}
\label{tbl:1}
\begin{tabular}{d{2.1} d{2.0} d{3.0} d{2.0} d{3.0}}
\toprule
\mc{S{\o}vnm{\ae}ngde} &
\multicolumn{2}{c}{Eleverne fra $9$.~A} &
\multicolumn{2}{c}{Eleverne fra $9$.~B}
\\
\midrule
& \mc{Abs.} & \mc{Rel.} & \mc{Abs.} &
\mc{Rel.} \\
\mc{\si{\hour}} & \mc{---} & \mc{\si{\percent}} & \mc{---} &
\mc{\si{\percent}} \\
\midrule
6.5 & 1 & 4 & 0 & 0
\\
7.0 & 4 & 16 & 2 & 10
\\
7.5 & 3 & 12 & 3 & 15
\\
8.0 & 8 & 32 & 9 & 45
\\
8.5 & 5 & 20 & 3 & 15
\\
9.0 & 2 & 8 & 3 & 15
\\
9.5 & 1 & 4 & 0 & 0
\\
10.0 & 1 & 4 & 0 & 0
\\
\midrule
\mc{I alt} & 25 & 100 & 20 & 100
\\
\bottomrule
\end{tabular}
\end{table}
\end{document}

Why are the second and third columns not horizontally centered relative to
"Eleverne fra 9. A" and the fourth and fifth columns not horizontally
centered relative to "Eleverne fra 9. B"? (They need to be pushed slightly
to the right.)
Update
I would like the width of the second and third column to be half the width
of the box containing "Eleverne fra 9. A", and the width of the fourth and
fifth column to be half the width of the box containing "Eleverne fra 9.
B".

No comments:

Post a Comment