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}
Result
The compiled example

Open in the editor

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}
Result
The compiled example

Open in the editor

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}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages