Tx · LaTeX & TikZ

How to Fix “Extra Alignment Tab” with \multicolumn

Published By the 9to5Science editorial team

At a glance

  1. 1. Count the columns

    Check the number of columns declared in the tabular preamble.

  2. 2. Count spanned columns

    Treat each multicolumn entry as occupying the number of columns in its first argument.

  3. 3. Check separators

    Make sure each row has the right number of cell separators and ends with \\.

The LaTeX message “Extra alignment tab has been changed to \cr” usually means that a row in a tabular environment has more & separators than the table can accommodate. The issue often appears when a row uses \multicolumn, because a spanning cell occupies multiple columns even though it is written as one cell.

Count the columns in the table preamble, then count the columns occupied by each row. A row may leave trailing columns empty, but it must not occupy more columns than the preamble provides. A \multicolumn entry counts as the number of columns specified in its first argument. The examples below show how to check that count and fix common causes.

How \multicolumn affects the column count

The syntax is:

\multicolumn{number of columns}{format}{cell contents}

For example, \multicolumn{2}{c}{Group} creates one cell that spans two columns and centers its contents. It still uses two columns in the table’s layout.

Suppose your table has four columns:

\begin{tabular}{|l|c|c|r|}

A row that begins with a cell spanning two columns can have at most two more one-column cells. To fill all four columns, use two:

\multicolumn{2}{|c|}{Group} & Value & Total \\

The entries account for four columns altogether: two for Group, one for Value, and one for Total. The row has two & separators because it contains three cell entries, even though those entries occupy four columns.

A complete working example

This table has four columns. Its first row groups the first two columns under one heading; the next row uses all four columns separately.

\documentclass{article}

\begin{document}

\begin{tabular}{|l|c|c|r|}
\hline
\multicolumn{2}{|c|}{Group} & Value & Total \\
\hline
A & B & 5 & 9 \\
\hline
\end{tabular}

\end{document}

The \multicolumn{2}{|c|}{Group} entry spans the first two columns. Its format argument, |c|, centers the heading and supplies vertical rules at its edges. The remaining Value and Total cells fill the third and fourth columns.

Find the extra tab

If your preamble declares four columns, a row must not occupy more than four columns; it may use fewer if trailing columns are intentionally left empty. For example, this row has too many:

\multicolumn{2}{c}{Group} & A & B & C \\

The first entry spans two columns, and the three following entries each use one. That adds up to five columns, not four. Remove one cell or change the span to match the intended layout.

A useful check is to count occupied columns, not just the number of & characters. For a row with entries that span s1,s2,…,sks_1, s_2, \ldots, s_k columns, the total must equal the number of columns when the row is intended to fill them all. If trailing columns are intentionally left empty, the total may be smaller, but it must not exceed the number of columns in the table:

s1+s2+⋯+sk≤number of columnss_1 + s_2 + \cdots + s_k \leq \text{number of columns}

For ordinary one-column cells, each sis_i is 1. A \multicolumn{3}{...}{...} entry has si=3s_i=3.

Other causes to check

  • An ampersand is part of the text. In LaTeX, & is a column separator inside a table. Write \& when you want to print an ampersand, as in Research \& Development.
  • The table preamble has fewer columns than the row needs. In \begin{tabular}{lcr}, for instance, there are three columns. Add a column specification or remove an unintended cell.
  • A row has a stray &. Check the end of the row and nearby commands for an extra separator.
  • A \multicolumn span is wrong. Its first argument should be the number of columns the cell is meant to cover, not the number of cells that follow it.
  • A nested table has its own alignment. When a cell contains another tabular, check the inner and outer tables separately. An & in an inner table belongs to that inner alignment, but an ungrouped or misplaced separator can disrupt the outer row.

Common mistakes with \multicolumn

A \multicolumn command must be the first item in the cell it modifies. Put text or formatting that belongs inside the cell in its third argument. For example, use \multicolumn{2}{c}{\textbf{Group}}, rather than placing \textbf{} before \multicolumn in the same cell.

Also check that the third argument is enclosed in braces and that rows are terminated with \\ when another row or a rule follows; the final row before \end{tabular} may omit it. The format argument replaces the normal alignment and border formatting for the columns covered by the span, so include any vertical rules you want in that argument. \multicolumn changes how a cell is formatted and how many columns it spans; it does not add columns to the table.

References

  1. LaTeX2e unofficial reference manual: \multicolumn

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.