4

I have some issues with the usage of \multicolumn. As can be seen on the screenshot below, the words 'Classical' and 'Squared' are correctly aligned in the centre of the column. The word 'Exponential' however is not centered properly.

enter image description here

The code is:

\begin{table}[]
\setlength{\tabcolsep}{12pt}
\centering
\begin{tabular}{l c c c c c c}
\hline\hline
\\\\[-4.3\medskipamount]
 & \multicolumn{2}{c}{Classic} & \multicolumn{2}{c}{Squared} & \multicolumn{2}{c}{Exponential} \\
\textit{a} & 70 & 30 & 70 & 30 & 70 & 30 \\ [0.5ex]
\hline
\\\\[-3.9\medskipamount]
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
S100 & 91 & 31 & 71 & 01 & 21 & 41 \\
[1ex] \hline
\end{tabular}
\end{table}

I would prefer to keep using the tabular package in the solution. Thank you in advance!

6

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} 

enter image description here

  • The \makebox[0pt] solution is working perfectly and is exactly what I'm looking for! Thank you so much for this! – Jérémy Aug 19 at 12:06
  • 1
    Just in case: if you already load mathtools, it defines a \clap command which does the same job and is shorter to type. – Bernard Aug 19 at 12:15
2

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}

enter image description here

  • I type of tabulars, you have three groups each of two columns. Those three groups should preferably be of the same width. – Sveinung Aug 20 at 6:20
2

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}

enter image description here

  • siunitx is an excellent package, but a little "overkill" when you have simple columns without decimals. – Sveinung Aug 19 at 17:44
  • @Sveinung,partly you are right, but it offer simple way to define column width with centered content :-) – Zarko Aug 19 at 17:46
  • What about w{c}{2em}? – Sveinung Aug 19 at 21:25
1

I would have used:

  1. The new w{<align>}{<wd>} column to fix the width of all column
  2. \setlength{\tabcolsep}{0.5em} (gives 1em space between columns)
  3. Trimmed cmidrule
  4. No side bearings (@{})
  5. One grade smaller fonts in the headings
  6. booktab-rules and addlinespace[<wd>]

enter image description here

And the MWE:

\documentclass{article}
\usepackage{booktabs, array, caption} 

\begin{document}

\begin{table}[ht]
\caption{A table with figures\label{tab:atable}}
\setlength{\tabcolsep}{0.5em}
\centering
\begin{tabular}{@{}w{l}{4em}*{6}{w{c}{2em}}@{}}
\toprule
 & \multicolumn{2}{c}{\small Classic} & \multicolumn{2}{c}{\small Squared} & \multicolumn{2}{c@{}}{\makebox[0pt]{\small Exponential}} \\\cmidrule(l{0.75em}r{0.75em}){2-3}\cmidrule(l{0.75em}r{0.75em}){4-5}\cmidrule(l{0.65em}){6-7}
\textit{a} & 70 & 30 & 70 & 30 & 70 & 30 \\ 
\midrule\addlinespace[1ex]
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}
  • 1
    (+1) What' s this new column specifier, w? I vaguely remember having seen a bunch of new specifiers mentioned recently, but I can't remember where nor when. Is it a new package? – Bernard Aug 19 at 22:12
  • @Bernard See array manual pages 2 and 3. You have w and W, with slightly different attributes. – Sveinung Aug 19 at 22:16
  • Thank you. This one is not new, but I've never used these specifiers. I've found the new series of specifiers (which I've not tested yet): they're defined in the new arraycols package. – Bernard Aug 19 at 22:28
  • @Bernard Thank you for the reference to the arraycols-package. I was not aware of this. – Sveinung Aug 19 at 22:53
  • It's very recent (july!). – Bernard Aug 19 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.