About these ads

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}

multicol-table

 

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}

multirow-table

 

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}

multicol-row-table

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}

cline-table

About these ads

4 Responses to “Multi-column and multi-row cells in LaTeX tables”

  • AlBundy

    Hi,

    in the multiple columns and multiple rows examples, are you sure pictures match with code?. I think alignment of “X” is not “c”.

  • Rachael

    Hi. Thanks for the help. I am having trouble with multiple multirows in a table. It doesn’t seem to recognise that the second multirow exists. Any ideas?

    • tom

      Hi Rachael,
      Here is an example with multiple multirows in a table. If this doesn’t help solving your issue, please provide a minimal example.

      Thanks, Tom

      \documentclass[11pt]{article}
      \usepackage{multirow}
      \begin{document}
      \begin{table}[ht]
      \caption{Multi-row table}
      \centering
      \begin{tabular}{ccc}
          \hline
          \multirow{2}{*}{Multirow}&X&\multirow{2}{*}{Multirow}\\
          &X&\\
          X&\multirow{2}{*}{Multirow}&\multirow{2}{*}{Multirow}\\
          X&&\\
          \hline
      \end{tabular}
      \label{tab:multirow}
      \end{table}
      \end{document}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 712 other followers

%d bloggers like this: