142

I have this table, but wanted to format the first row. I like to match the two columns of first row, and last two columns of the same first row. Any suggestion on how to do that?

\begin{table}[!h] 
\caption{Comparison of percentages.}
\begin{tabular}{lclclclclc}
\hline
\hline 
Mode &  Var  &  Cum\\
\hline
{}       & EF   & CHF    & EF2   & CHF2\\
1   &  17.5 & 19.1   & 17.5  & 19.1\\
2   &  11.8 & 12.7   & 29.3  &  31.9\\
3   &  6.6  &  5.6         & 35.9    &  37.4\\
\hline
\end{tabular}
\end{table}
1

3 Answers 3

189

This can be done using \multicolumn:

\multicolumn{<no of columns>}{<column alignment>}{<content>}

As an example, with some improvements using booktabs:

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\setlength{\heavyrulewidth}{1.5pt}
\setlength{\abovetopsep}{4pt}
\begin{document}
\begin{table}[!htbp]
\centering
\caption{Comparison of percentages.}
\begin{tabular}{*5c}
\toprule
Mode &  \multicolumn{2}{c}{Var} & \multicolumn{2}{c}{Cum}\\
\midrule
{}   & EF   & CHF    & EF2   & CHF2\\
1   &  17.5 & 19.1   & 17.5  & 19.1\\
2   &  11.8 & 12.7   & 29.3  & 31.9\\
3   &  6.6  &  5.6   & 35.9  & 37.4\\
\bottomrule
\end{tabular}
\end{table}
\end{document}

table with merged cells

5
  • @ Stefan Kottwitz: Thank you very much! This is amazing! Is it possible to shift the Mode back to first column and Var on top of 2nd/3rd columns?
    – BrettHarry
    Jul 12, 2011 at 11:58
  • 1
    @BrettHarry: no problem, just apply \multicolumn to Var instead, I modified the example.
    – Stefan Kottwitz
    Jul 12, 2011 at 12:32
  • 1
    @BrettHarry Mori's paper and booktabs documentation can help you design good tables.
    – pmav99
    Jul 12, 2011 at 16:07
  • Is it also possible to add a linebreak to a \multicolumn? Feb 14, 2018 at 16:13
  • If you have vertical lines in your table, you need to use \multicolumn{2}{c|}{text} (not that it's c| instead of just c) (Source). May 9, 2023 at 9:00
47
\multicolumn{<no of columns>}{<column type>}{<stuff>}

there are a lot of examples if you search for this topic

2
  • 5
    I wish this answer was merged into the accepted one as a small prefix May 24, 2018 at 14:10
  • merging accomplished
    – Teepeemm
    Sep 3, 2021 at 1:05
2

An alternative solution with tabularray package:

\documentclass{article}

\usepackage{caption}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\setlength{\heavyrulewidth}{1.5pt}

\begin{document}

\begin{table}[!htbp]
\centering
\caption{Comparison of percentages.}
\begin{tblr}{
  colspec = {crrrr},
  cell{1}{2,4} = {c=2}{c}, % multicolumn (column number=2, center alignment)
}
\hline[2pt]
  Mode &   Var &      &  Cum &      \\
\hline[1pt]
       &    EF &  CHF &  EF2 & CHF2 \\
\cline{2-5}
    1  &  17.5 & 19.1 & 17.5 & 19.1 \\
    2  &  11.8 & 12.7 & 29.3 & 31.9 \\
    3  &   6.6 &  5.6 & 35.9 & 37.4 \\
\hline[2pt]
\end{tblr}
\end{table}

\begin{table}[!htbp]
\centering
\caption{Comparison of percentages.}
\begin{booktabs}{
  colspec = {crrrr},
  cell{1}{2,4} = {c=2}{c}, % multicolumn (column number=2, center alignment)
}
\toprule
  Mode &   Var &      &  Cum &      \\
\midrule
       &    EF &  CHF &  EF2 & CHF2 \\
\cmidrule[lr]{2-3}\cmidrule[lr]{4-5}
    1  &  17.5 & 19.1 & 17.5 & 19.1 \\
    2  &  11.8 & 12.7 & 29.3 & 31.9 \\
    3  &   6.6 &  5.6 & 35.9 & 37.4 \\
\bottomrule
\end{booktabs}
\end{table}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .