Que signifie l'erreur: « Extra alignment tab has been changed to \cr »?

• Message: Extra alignment tab has been changed to \cr
• Origine: TeX.

Lorsqu'on utilise une structure d'alignement, telle que tabular, ou l'un des environnements mathématiques hors-texte (par exemple, eqnarray ou split de l'extension amsmath), chaque ligne est alors divisée en un nombre défini de colonnes séparées par des signes &. L'erreur signifie que ces caractères sont trop nombreux, sans doute à cause de l'oubli d'un \\ indiquant la fin d'une ligne (le nom pour cette fin de ligne est \cr, mais il n'est pas totalement équivalent à \\).

This is an error you may encounter in LaTeX when a tabular environment is being processed. “Alignment tabs” are the & signs that separate the columns of a tabular (or array or matrix) environment; so the error message

! Extra alignment tab has been changed to \cr

could arise from a simple typo, such as:

\begin{tabular}{ll}
hello   & there & jim \\
goodbye & now
\end{tabular}

where the second & in the first line of the table is more than the two-column ll column specification can cope with. In this case, an extra l in that solves the problem. (If you continue from the error in this case, jim will be moved to a row of his own.) Another simple typo that can provoke the error is:

\begin{tabular}{ll}
hello   & there
goodbye & now
\end{tabular}

where the \\ has been missed from the first line of the table. In this case, if you continue from the error, you will find that LaTeX has made a table equivalent to:

\begin{tabular}{ll}
hello   & there goodbye\\
now
\end{tabular}

(with the second line of the table having only one cell).

Rather more difficult to spot is the occurrence of the error when you're using alignment instructions in a p column:

\usepackage{array}
...
\begin{tabular}{l>{\raggedright}p{2in}}
here & we are again \\
happy & as can be
\end{tabular}

the problem here (as explained in tabular cell alignment) is that the \raggedright command in the column specification has overwritten tabulars definition of \\, so that happy appears in a new line of the second column, and the following & appears to LaTeX just like the second & in the first example above.

Get rid of the error in the way described in tabular cell alignment — either use \tabularnewline explicitly, or use the \RBS trick described there.

The amsmath package adds a further twist; when typesetting a matrix (the package provides many matrix environments), it has a fixed maximum number of columns in a matrix — exceed that maximum, and the error will appear. By default, the maximum is set to 10, but the value is stored in counter MaxMatrixCols and may be changed (in the same way as any counter):

\setcounter{MaxMatrixCols}{20}

Sources:

• LaTeX Companion, 2e édition, Frank Mittelbach, Michel Goossens, Johannes Braams, David Carlisle, Chris Rowley (Pearson, 2006) ; ISBN: 978-2-7440-7182-9. Annexe B, Détecter et résoudre les problèmes, reproduite avec l'aimable autorisation de l'éditeur.
2_programmation/erreurs/e/extra_alignment_tab_has_been_changed_to_cr.txt · Dernière modification: 2021/01/13 00:20 par jejust