How to Use Multirow and Multicolumn Together in LaTeX
At a glance
- 1. Load the package
Add the multirow package to your document preamble.
- 2. Combine the commands
Put multicolumn first, then place multirow inside its cell text.
- 3. Reserve later cells
In each row covered by the multirow, leave the occupied columns empty.
- 4. Draw partial rules
Use cline to draw horizontal rules only across columns not covered by the merged cell.
You can combine \multirow and \multicolumn when a table cell needs to span both rows and columns. The reliable pattern is to make \multicolumn the cell command and put \multirow inside its text argument. This lets LaTeX apply the column-spanning layout to the cell while the inner command makes its contents span rows.
The command pattern
The two commands control different directions:
\multicolumn{n}{format}{text}spansncolumns in the current row. Itsformatargument sets the alignment and any vertical rules for the merged cell.\multirow{n}{width}{text}spansnrows. It comes from themultirowpackage. Use*for the width when you want the natural width of the contents.
For a cell spanning two rows and two columns, combine them like this:
\multicolumn{2}{|c|}{\multirow{2}{*}{Label}}
The outer \multicolumn must be at the start of the table cell so LaTeX can recognize the column span. The \multirow command then produces the cell contents inside that span. The vertical-bar characters in |c| request a left and right rule; adjust this format to suit your table.
Complete example
This example has a cell labeled “Region” spanning the first two columns and two rows. “Results” spans the last two columns in the first row.
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|c|c|c|c|}
\hline
\multicolumn{2}{|c|}{\multirow{2}{*}{Region}} &
\multicolumn{2}{c|}{Results} \\
\cline{3-4}
\multicolumn{2}{|c|}{} & First & Second \\
\hline
North & East & 12 & 15 \\
South & West & 9 & 11 \\
\hline
\end{tabular}
\end{document}
Compile this with a standard LaTeX installation that includes the multirow package. The package is loaded in the preamble with \usepackage{multirow}. In the first table row, \multicolumn{2}{|c|}{...} occupies columns one and two, and the nested \multirow{2}{*}{Region} makes its contents extend through the next row. The second \multicolumn combines columns three and four for the heading “Results.”
The next row begins with an empty \multicolumn{2}{|c|}{} continuation, followed by First and Second in columns three and four. This continuation occupies the first two columns without an internal vertical rule, while the “Region” contents extend through the row. The \cline{3-4} draws a rule only beneath columns three and four, rather than across the merged cell.
The two data rows show ordinary four-column entries after the header. They are separate from the header’s multirow span, which covers only the first and second header rows.
Why the order matters
A table row is parsed as a sequence of cells separated by &. \multicolumn is a special instruction that changes how the current cell occupies columns, so put it first in that cell. If you put \multirow outside and try to put \multicolumn inside it, LaTeX may not treat the inner command as the instruction for the table cell’s column span.
Think of the combined cell as one cell with two layout requirements: the outer command handles the horizontal span, and the inner command handles the vertical span. The commands do not automatically fill or remove entries in other rows. You must keep the row structure consistent yourself.
Common mistakes
- Reversing the nesting: Start the cell with
\multicolumn, then nest\multirowinside its third argument. - Forgetting later-row placeholders: A
\multirowdoes not remove the entries needed to reach later columns. In the example, an empty\multicolumn{2}{|c|}{}in the second header row reserves columns one and two and suppresses their internal vertical rule. - Using the wrong rule: A full
\hlineafter the first header row would draw through the area occupied by the multirow cell. Use\cline{3-4}to rule only columns three and four. The range is inclusive. - Miscounting columns: Count the columns taken up by each multicolumn cell when checking a row. A cell with
\multicolumn{2}{...}{...}replaces two ordinary cells in that row. - Forgetting the package:
\multirowis not part of the basictabularenvironment. Loadmultirowin the preamble or LaTeX will report an undefined command. - Expecting automatic vertical alignment:
\multirow{2}{*}{...}centers the contents vertically across the rows by default. If the result looks crowded, adjust the row height or use the package’s optional vertical-position argument rather than adding arbitrary blank rows.
If the cell needs a fixed width so its text wraps, replace * with a width such as 2cm, as in \multirow{2}{2cm}{Long label}. The multicolumn format still controls the cell’s alignment and borders; the multirow width controls the text box used for its contents.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.