Tables

How to Merge Cells in a LaTeX Table with multicolumn and multirow

Merge LaTeX table cells across columns with multicolumn and down rows with multirow, with compile-ready examples, line tips and common error fixes.

On this page
  1. Merge cells across columns with \multicolumn
  2. Set alignment and borders on a merged cell
  3. Merge cells down rows with \multirow
  4. Draw lines around merged cells
  5. Merging across rows and columns
  6. Complete example
  7. Common errors and fixes

LaTeX has no merge button for tables. You merge cells with two commands instead. \multicolumn joins cells across columns in the same row and is built into LaTeX. \multirow joins cells down several rows and needs the multirow package. This guide shows the syntax for each, how to control the lines around merged cells, and how to fix the errors that usually appear.

Merge cells across columns with \multicolumn

The syntax is:

\multicolumn{number of columns}{alignment}{content}

The first argument is how many columns the cell spans. The second is the alignment of the merged cell, such as c, l or r, and it can include vertical bars. The third is the content. Here is a header spanning two of three columns:

\begin{tabular}{|c|c|c|}
  \hline
  \multicolumn{2}{|c|}{Merged header} & Column 3 \\
  \hline
  A1 & A2 & A3 \\
  \hline
\end{tabular}

The first row has two cells, but the merged cell counts as two columns, so the row still matches the three-column specification. Every row needs to add up to the same number of columns.

Set alignment and borders on a merged cell

The bars inside the alignment argument set the lines at the outer edges of the merged cell. In the example, |c| puts a line on the left and right of the merged cell. Bars that fall inside the span are ignored, so the merged cell has no inner dividers.

If the alignment argument has no bars, the merged cell has no line on its outer edges, even where the column specification has bars. Include the bars when you want those edges drawn.

Text styling works inside the content argument, for example \multicolumn{2}{|c|}{\textbf{Merged header}}. For more on fonts and styles, see LaTeX table formatting: fonts, sizes and styles.

Merge cells down rows with \multirow

\multirow is in the multirow package, so add it to the preamble:

\usepackage{multirow}

The syntax is:

\multirow{number of rows}{width}{content}

Use * for the width to let LaTeX use the content’s natural width. Each row covered by the merged cell, apart from the first, needs an empty first cell followed by &, so the remaining cells stay in their columns:

\begin{tabular}{|c|c|c|}
  \hline
  \multirow{2}{*}{Group} & Item A & 10 \\
  \cline{2-3}
   & Item B & 20 \\
  \hline
\end{tabular}

\multirow centers its content vertically by default. The optional argument changes that: \multirow[t]{2}{*}{...} aligns to the top, and [b] aligns to the bottom.

Draw lines around merged cells

\hline draws a line across the full width of the table. \cline{2-3} draws a line only across columns 2 and 3. In the example above, the line stops before column 1, so the merged Group cell stays open between its two rows.

If you use the booktabs package, use \cmidrule for partial lines instead of \cline.

Merging across rows and columns

\multicolumn cannot span rows, and \multirow cannot span columns. A single block that covers several rows and several columns needs a more involved construction, which this article does not cover. For most tables, a header merged across columns plus a label merged down rows is enough.

Complete example

This document combines both commands. It is a standard article document:

\documentclass{article}
\usepackage{multirow}

\begin{document}

\begin{tabular}{|c|c|c|}
  \hline
  \multicolumn{3}{|c|}{Sales by region} \\
  \hline
  \multirow{2}{*}{Region} & \multicolumn{2}{|c|}{Q1} \\
  \cline{2-3}
   & Units & Revenue \\
  \hline
  North & 120 & 4,300 \\
  South & 95 & 3,800 \\
  \hline
\end{tabular}

\end{document}

Common errors and fixes

  • ! Undefined control sequence at \multirow. The multirow package is not loaded. Add \usepackage{multirow} to the preamble.
  • Extra alignment tab has been changed to \cr. The row has more cells than the table has columns. Count the cells in that row, counting each \multicolumn by its span, and compare the total with the column specification.
  • Cells after a merged cell shift left. A row under a \multirow cell is missing its empty first cell. Add an empty cell followed by &.
  • A line runs through a merged cell. Replace the \hline with a \cline{...} covering only the columns that should show a line.

The complete guide to tables

LaTeX Table Formatting: Fonts, Sizes and Styles
Read the guide

Keep exploring

Guides from other topics

All topics →