Use the multirow package to merge cells vertically across multiple rows
To merge two rows in a LaTeX table, you need the multirow package and the \multirow command. This command stacks cells vertically so that one cell spans the height of multiple rows below it. The syntax is straightforward: \multirow{number_of_rows}{width}{content}, where the number of rows tells LaTeX how many rows to span, the width sets the cell width (or * for automatic), and the content is what appears in the merged cell.
The most common setup uses \usepackage{multirow} at the top of your document, then places \multirow in the first row of the group you want to merge. The rows below that position lose their content in that column — LaTeX handles the vertical alignment automatically.
Key Takeaways
- Add \usepackage{multirow} to your document preamble before using the multirow command.
- Place \multirow{2}{*}{text} in the first row of the pair, using 2 for two rows and * for automatic width.
- Leave the corresponding cell empty in the second row — do not put content there or the merge breaks.
- Multirow works with any table environment (tabular, table, longtable) as long as the package is loaded.
- For horizontal merging across columns, use \multicolumn instead; multirow handles only vertical merging.
Basic syntax and package setup
Start by adding the multirow package to your document preamble. Open your .tex file and place this line in the header section before \begin{document}:
\usepackage{multirow}
Without this package, the \multirow command will not work and LaTeX will return an error. Once loaded, you can use \multirow in any table environment in that document.
The command itself takes three arguments. The first argument is the number of rows to span — use 2 to merge two rows, 3 to merge three rows, and so on. The second argument is the width of the merged cell; use * to let LaTeX calculate the width automatically based on content. The third argument is the text or content that appears in the merged cell.
Placing multirow in your table structure
Put the \multirow command in the first row of the rows you want to merge. Here is a working example that merges two rows in the first column:
\begin{tabular}{|c|c|c|}\hline \multirow{2}{*}{Merged} & Data 1 & Data 2 \\ \hline & Data 3 & Data 4 \\ \hline \end{tabular}
Notice that the second row has an empty cell in the first column — this is required. If you put content there, the merge fails and the table breaks. The empty cell tells LaTeX that this position is already occupied by the multirow cell above it.
The \hline commands draw horizontal lines. When you merge rows, the line between the merged rows disappears automatically, which is usually the desired behavior. If you need a line in a specific place, you can use \cline{column_range} to draw a line across only certain columns.
Controlling width and alignment
The second argument of \multirow controls the cell width. Using * (asterisk) tells LaTeX to measure the content and set the width automatically. This works well for short text. For longer content or specific formatting, replace the * with a fixed width like 2cm or 1.5in.
\multirow{2}{2cm}{This is a longer piece of text}
By default, multirow centers the content vertically within the merged cell. If you need different alignment, you can add an optional argument. Use \multirow{2}{*}[offset]{content} where offset is a number of lines to shift the content up or down. Positive numbers move content down, negative numbers move it up.
For horizontal alignment within the merged cell, wrap your content in a minipage or use \raggedright, \centering, or \raggedleft before the text. This gives you control over left, center, or right alignment independent of the vertical merge.
Merging multiple rows at once
You can merge more than two rows by changing the first argument. To merge three rows, use \multirow{3}{*}{content}. The pattern stays the same: place the command in the first row, then leave the corresponding cell empty in each row below.
\begin{tabular}{|c|c|}\hline \multirow{3}{*}{Three Rows} & Row 1 \\ \hline & Row 2 \\ \hline & Row 3 \\ \hline \end{tabular}
You can also merge rows in multiple columns at the same time. Each column that needs merging gets its own \multirow command in the first row, and each subsequent row leaves those cells empty. This creates a block of merged cells rather than a single column.
Combining multirow with multicolumn
Sometimes you need to merge both rows and columns in the same table. Use \multirow for vertical merging and \multicolumn for horizontal merging. When a cell needs both, place \multirow inside \multicolumn:
\begin{tabular}{|c|c|c|}\hline \multicolumn{2}{|c|}{\multirow{2}{*}{Merged}} & Data \\ \hline \multicolumn{2}{|c|}{} & More Data \\ \hline \end{tabular}
The order matters: \multicolumn goes on the outside, \multirow on the inside. This tells LaTeX to first span columns, then span rows within that span. Leave the cells empty in both the rows below and the columns to the right, depending on which directions you are merging.
Common issues and fixes
If your merged cell appears misaligned or the text does not show, check that you left the corresponding cells empty in the rows below. Content in those cells will overwrite the merge. Also verify that \usepackage{multirow} is in your preamble — forgetting this is the most common error.
If horizontal lines appear where you do not want them, use \cline instead of \hline to draw lines only across certain columns. For example, \cline{2-3} draws a line across columns 2 and 3 only, leaving column 1 blank. This prevents lines from cutting through merged cells.
If the merged text appears too high or too low, use the optional offset argument: \multirow{2}{*}[-0.5]{content} to adjust vertical position. Negative values move text up, positive values move it down. Experiment with small increments like 0.5 or 1 to find the right position.
Frequently Asked Questions
Can I merge rows in a longtable environment?
Yes, multirow works with longtable. The syntax is identical — add \usepackage{multirow} and use \multirow the same way. However, if your merged cell spans a page break, the merge may not display correctly. For tables that break across pages, consider keeping merged cells on a single page.
What is the difference between multirow and multicolumn?
Multirow merges cells vertically (down the page), while multicolumn merges cells horizontally (across columns). Use \multirow{2}{*}{text} to span rows and \multicolumn{2}{c}{text} to span columns. You can combine both in the same cell if needed.
How do I add a border around a merged cell?
Borders come from the table structure itself — the | characters in your tabular definition and \hline or \cline commands. When you merge cells, the borders follow the outer edges of the merged area. Use \cline{column_range} to draw lines only where you want them, avoiding lines that cut through merged cells.
Can I merge rows without using multirow?
Technically yes, but it is difficult. You could use nested tables or manual spacing, but multirow is the standard LaTeX solution and produces cleaner code. It is worth the one-line package addition to your preamble.
Why does my merged cell text disappear?
This usually means you put content in the cells below the merged cell. LaTeX interprets that content as overwriting the merge. Delete the content from those cells and leave them empty — just use & & to skip to the next column.