Multicolumn in table not centered
The reason is that this word is a bit too long. Of course, you can increase the value of \tabcolsep
. Another solution uses a \makebox[0pt]
, which allows the word to overlap slightly into the inter-column space, symmetrically.
Other than that,I recommend using the rules from booktabs
, which have a variable thickness, and add some vertical padding around the rules. This will save you from adjusting by hand through spacing:
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[]
\setlength{\tabcolsep}{12pt}
\centering
\begin{tabular}{l c c c c c c}
\toprule\midrule
& \multicolumn{2}{c}{Classic} & \multicolumn{2}{c}{Squared} & \multicolumn{2}{c}{\makebox[0pt]{Exponential}} \\
\textit{a} & 70 & 30 & 70 & 30 & 70 & 30 \\ [0.5ex]
\midrule
\\\\[-3.9\medskipamount]
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
The problem with using \makebox[0pt]{}
is that, as Bernard said, the long header will overlap the inter-column spacing which may seem quite ugly. To avoid this, the sum of the widths of the two numeric columns should at least be equal to the width of the long header. This can be exactly calculated and defined in a new column type C
as follows.
\documentclass[12pt,a4paper]{article}
\usepackage{booktabs, array}
\begin{document}
\begin{table}
\setlength{\tabcolsep}{12pt}
\newlength\wexp
\settowidth{\wexp}{Exponential}
\newcolumntype{C}{>{\centering\arraybackslash}p{\dimexpr.5\wexp-\tabcolsep}}
\centering
\begin{tabular}{l c c c c C C}
\toprule
& \multicolumn{2}{c}{Classic} & \multicolumn{2}{c}{Squared} & \multicolumn{2}{c}{Exponential} \\
\textit{a} & 70 & 30 & 70 & 30 & 70 & 30 \\ \midrule
S100 & 91 & 31 & 71 & 01 & 11 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
I would use S
column type from the siunitx
package, determine S
column width and add \cmidrule
below multi column cells:
\documentclass[12pt,a4paper]{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{l *{6}{S[table-format=2,
table-column-width=2em]}
}
\toprule
& \multicolumn{2}{c}{Classic}
& \multicolumn{2}{c}{Squared}
& \multicolumn{2}{c}{Exponential} \\
\cmidrule{2-3}\cmidrule(lr){4-5}\cmidrule{6-7}
\textit{a} & 70 & 30 & 70 & 30 & 70 & 30 \\
\midrule
S100 & 91 & 31 & 71 & 01 & 11 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}