texblog

Multi-column and multi-row cells in LaTeX tables

I always forget how to do this. If you have the same problem, here is a quick post for your bookmarks…

 

Basic commands
%multi-column
\multicolumn{number cols}{align}{text} % align: l,c,r

%multi-row
\usepackage{multirow}

\multirow{number rows}{width}{text}

Using * as width in the multirow command, the text argument’s natural width is used (multirow package documentation).

 

Multiple columns
\documentclass[11pt]{article}
\begin{document}

\begin{table}[ht]
\caption{Multi-column table}
\begin{center}
\begin{tabular}{cc}
	\hline
	\multicolumn{2}{c}{Multi-column}\\
	X&X\\
	\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}

\end{document}

 

Multiple rows
\documentclass[11pt]{article}
\usepackage{multirow}
\begin{document}

\begin{table}[ht]
\caption{Multi-row table}
\begin{center}
\begin{tabular}{cc}
	\hline
	\multirow{2}{*}{Multirow}&X\\
	&X\\
	\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}

\end{document}

 

Multiple rows and columns
\documentclass[11pt]{article}
\usepackage{multirow}
\begin{document}

\begin{table}[ht]
\caption{Multi-column and multi-row table}
\begin{center}
\begin{tabular}{ccc}
	\hline
	\multicolumn{2}{c}{\multirow{2}{*}{Multi-col-row}}&X\\
	\multicolumn{2}{c}{}&X\\
	\hline
	X&X&X\\
	\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}

\end{document}

The examples provided are very basic. Drop me a comment below in case you are having problems with a more complex table. Also, the color is just for illustration purposes and for simplicity reasons not part of the minimal working examples above. See here for how to color table columns or rows.

 

Partial horizontal line

Use \cline{columns} for a horizontal line spanning one or several table columns.

\documentclass[11pt]{article}
\begin{document}

\begin{table}[ht]
\caption{Partial horizontal line}
\begin{tabular}{ccc}
	\hline
	\multicolumn{2}{c}{Multi-column}&\\
	\cline{1-2}
	X&X&X\\
	X&X&X\\
	\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}

\end{document}

Exit mobile version