Spanning columns and rows in LaTeX

This article was originally from nithia.net that I decided to shut down since I had stopped developing it. However, this was a very popular article that I decided to keep.

The article describes how you create table cells that spans columns or rows in LaTeX, the LaTeX equivalent of colspan and rowspan in HTML.

Multirow

To be able to do this you need a package called multirow. The commands you use to create spanning cells are \multirow and \multicolumn.

\multirow usage

This command accepts three arguments: The number of rows the cell should span, the width of the cell itself and the content of the cell. You give the arguments like this: \multirow{number of rows}{width}{content}.

You don’t have to set a specific width for the cell, but can let LaTeX determine a good size by passing an asterix (*) as the width argument.

PS: When you use \multirow you have to make sure that you don’t fill the cells in the next rows you’re spanning with content.

\multicolumn usage

Like \multirow, \multicolumn takes three arguments, but they’re not quite the same. The arguments it takes are: Number of columns to span, placement of the content within the cell and the content of the cell. Use it like this: \multicolumn{number of columns}{placement}{content}.

\begin{tabular}{|l|l|r|}
  \hline
  \multicolumn{3}{|c|}{Cell spanning three columns} \\
  \hline
  \multirow{2}{*}{Cell spanning two rows}  & Cells  & being \\
      & spanned & here \\
  \hline
\end{tabular}

Note that the row after \multirow is used starts with a &, basically leaving the first cell blank. This is necessary since the content of this cell is already covered by the \multirow command above. If the cell spanning multiple rows is not the first you will obviously have to leave an empty cell where applicable in your table.