Extra alignment tab has been changed to \cr
This error occurs when LaTeX is typesetting a table and detects an alignment character (&
) where it did not expect to find one. LaTeX uses alignment characters to separate table columns and will complain if a table tries to use more columns than expected.
Error caused by the tabular environment
The tabular environment is a common source of this error, as demonstrated by the next example. Here, we have written {c|c|c}
to specify a table with three (centered) columns, meaning each table row should contain three cells.
\begin{tabular}{c|c|c} % Specify 3 centered columns
1 & 2 & 3 & 4\\ % ERROR: Uses 4 columns, not 3
5 & 6 & 7\\
\end{tabular}
Open this error-generating example in Overleaf
Our example generates the following error message:
and typesets this table:
Explanation of the error
The first &
in a table row indicates the start of the second column; consequently, for a three-column table LaTeX expects to see two alignment characters before each line break (\\
). However, the first row of our table uses three alignment characters which confuses LaTeX, making it change the unexpected alignment character to the \cr
command—an attempt to reduce the number of columns to three. Note that using three alignment characters requires four columns.
How to fix the error
To resolve this error and fix our table, we can either:
- remove the extra column by deleting the entry
- add an extra column to the tabular environment options (e.g., writing
{c|c|c|c}
) - create a new line (new table row)
Here is an example demonstrating each of these each solutions:
\section*{Removing the extra column entry}
\begin{center}
\begin{tabular}{c|c|c}
1 & 2 & 3\\
5 & 6 & 7\\
\end{tabular}
\end{center}
\section*{Adding an extra column to the tabular}
\begin{center}
\begin{tabular}{c|c|c|c}
1 & 2 & 3 & 4\\
5 & 6 & 7\\
\end{tabular}
\end{center}
\section*{Creating a new line (new table row)}
\begin{center}
\begin{tabular}{c|c|c}
1 & 2 & 3 \\
4 & & \\
5 & 6 & 7 \\
\end{tabular}
\end{center}
This example produces the following output:
Errors caused by math environments
Mathematical typesetting often requires the alignment of math elements, which is achieved using environments such as array
, matrix
, and several others. Some math environments can trigger the extra alignment tab error because they use a table to perform their alignment, as demonstrated in the following examples.
The array environment
LaTeX will generate an error if the number of alignment tabs used in an array row exceeds the number of array columns. Here is an example using an array with three columns but the first row tries to use four columns:
\[
\begin{array}{lcl}
g(x) & = & (x+2)^2 & = (x+2)(x+2)\\ % This row triggers the error
& = & x^2+4x+4\\
\end{array}
\]
Open this error-generating example in Overleaf
This example generates the following error message:
and typesets this array:
\[ \begin{array}{lcl} g(x) & = & (x+2)^2 \\ =(x+2)(x+2) \\ & = & x^2+4x+4\\ \end{array} \]
To correct this error, rewrite the array as follows:
\[
\begin{array}{lcl}
g(x) & = & (x+2)^2 \\
& = & (x+2)(x+2) \\
& = & x^2+4x+4\\
\end{array}
\]
Open this corrected example in Overleaf
The corrected array produces the following:
\[ \begin{array}{lcl} g(x) & = & (x+2)^2 \\ & = & (x+2)(x+2) \\ & = & x^2+4x+4\\ \end{array} \]
The amsmath
matrix environments
The amsmath
package provides numerous environments for typesetting matrices, including matrix
, pmatrix
, bmatrix
, Bmatrix
, vmatrix
, and Vmatrix
.
The following pmatrix
example tries to use 12 columns but generates an error because amsmath
sets a default maximum of 10 columns in typeset matrices.
\documentclass{article}
\usepackage{amsmath} % To access the matrix environment
\begin{document}
\[
\begin{pmatrix}
a_{1,1} & a_{1,2} & a_{1,3} & a_{1,4} & a_{1,5} & a_{1,6} & a_{1,7} & a_{1,8} & a_{1,9} & a_{1,10} & a_{1,11} & a_{1,12} \\
\end{pmatrix}
\]
\end{document}
Open this error-generating example in Overleaf
To fix the error, change the column-maximum to 12 by writing \setcounter{MaxMatrixCols}{12}
, or any value of your choice.
\documentclass{article}
\usepackage{amsmath} % To access the pmatrix environment
\setcounter{MaxMatrixCols}{12}
\begin{document}
\[
\begin{pmatrix}
a_{1,1} & a_{1,2} & a_{1,3} & a_{1,4} & a_{1,5} & a_{1,6} & a_{1,7} & a_{1,8} & a_{1,9} & a_{1,10} & a_{1,11} & a_{1,12} \\
\end{pmatrix}
\]
\end{document}
Open this corrected example in Overleaf
The corrected example produces the following matrix:
\[ \begin{pmatrix} a_{1,1} & a_{1,2} & a_{1,3} & a_{1,4} & a_{1,5} & a_{1,6} & a_{1,7} & a_{1,8} & a_{1,9} & a_{1,10} & a_{1,11} & a_{1,12} \\ \end{pmatrix} \]
A short note on the \cr command
LaTeX addresses the issue of an unexpected alignment character by substituting it with a fundamental command known as \cr
, which is integral to LaTeX's internal mechanics for concluding a table row. Although users utilize the LaTeX \\
macro to indicate the end of a table row, it is actually the \cr
command that is executed behind the scenes to terminate the row when the \\
macro is processed.
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Using the Overleaf project menu
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Using the History feature
- Debugging Compilation timeout errors
- How-to guides
- Guide to Overleaf’s premium features
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Matrices
- Fractions and Binomials
- Aligning equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
- Using the Symbol Palette in Overleaf
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management with bibtex
- Bibliography management with natbib
- Bibliography management with biblatex
- Bibtex bibliography styles
- Natbib bibliography styles
- Natbib citation styles
- Biblatex bibliography styles
- Biblatex citation styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- Multilingual typesetting on Overleaf using babel and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections, equations and floats
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typesetting exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class