Merge table cells in LaTeX (multicolumn, multirow)
\multicolumn merges cells across columns and is part of LaTeX. Merging across rows needs \multirow from the multirow package.
Preamble
The snippets on this page need these lines before \begin{document}:
\usepackage{multirow}Merge across columns
\multicolumn{2}{c}{text} takes the number of columns, the alignment of the merged cell (l, c or r, with | for vertical lines) and the content.
\begin{tabular}{|l|c|c|}
\hline
Name & \multicolumn{2}{c|}{Score} \\
\hline
& Test 1 & Test 2 \\
\hline
Anna & 12 & 15 \\
\hline
\end{tabular}Merge across rows
\multirow{2}{*}{text} takes the number of rows, the width (* means the natural width) and the content. Leave the cells below it empty, and use \cline so the horizontal line skips the merged cell.
\begin{tabular}{|l|l|c|}
\hline
\multirow{2}{*}{Group A} & Anna & 12 \\
\cline{2-3}
& Ben & 15 \\
\hline
\end{tabular}Merge rows and columns at once
Put \multirow inside \multicolumn, never the other way round. The row below needs an empty \multicolumn of the same width.
\begin{tabular}{|c|c|c|}
\hline
\multicolumn{2}{|c|}{\multirow{2}{*}{Block}} & 1 \\
\cline{3-3}
\multicolumn{2}{|c|}{} & 2 \\
\hline
\end{tabular}Pitfalls
\multicolumn{1}{c}{text}changes the alignment of a single cell without merging anything.- A colored row from
colortblpaints over a\multirowcell that starts in an earlier row. Give\multirowa negative row count and put it in the last row of the block.
Compiled with pdfLaTeX from TeX Live 2023.
Related pages
- Package
multirow - Package
booktabs - How-to Create a table in LaTeX
- Error Extra alignment tab has been changed to \cr