> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/latex/zh-cn/latex-cuo-wu/07-extra-alignment-tab-has-been-changed-to-cr.md).

# 多余的对齐制表符已更改为 \cr

当 LaTeX 在排版表格并检测到一个对齐字符（`&`）而它并未预期出现时，就会发生此错误。LaTeX 使用对齐字符来分隔表格列，并会 [报错](#a-short-note-on-the-cr-command) 如果表格尝试使用比预期更多的列。

## 由 tabular 环境引起的错误

tabular 环境是此错误的常见来源，如下一个示例所示。这里，我们写了 `{c|c|c}` 来指定一个包含三列（居中列）的表格，这意味着每一行都应包含三个单元格。

```latex
\begin{tabular}{c|c|c} % Specify 3 centered columns
   1 & 2 & 3 & 4\\ % ERROR: Uses 4 columns, not 3
   5 & 6 & 7\\
\end{tabular}
```

[打开此 **会产生错误的** Overleaf 中的示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+a+tabular+with+too+many+alignment+characters\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Btabular%7D%7Bc%7Cc%7Cc%7D+%25+Specify+3+centered+columns%0A+++1+%26+2+%26+3+%26+4%5C%5C+%25+ERROR%3A+Uses+4+columns%2C+not+3%0A+++5+%26+6+%26+7%5C%5C%0A%5Cend%7Btabular%7D%0A%5Cend%7Bdocument%7D)

我们的示例会生成以下错误消息：

![演示 LaTeX 表格错误 “Extra alignment tab has been changed to \cr”](/files/a5e28d3370e94aea11e8e1a4ac224cb13ff1a548)

并排版出这个表格：

![](/files/89a6c49f88a092c1700d9cc4c801102260507784)

### 错误说明

第一个 `&` 在表格行中 *第二次* 表示……列的开始；因此，对于一个三列表格，LaTeX 期望在每个换行符（ *路径元素：* ）之前看到`\\`对齐字符。然而，我们表格的第一行使用了 *三* 个对齐字符，这让 LaTeX 感到困惑，于是它将这个意外的对齐字符改为 [`\cr` 命令](#a-short-note-on-the-cr-command)——试图将列数减少到三列。请注意，使用 *三* 个对齐字符需要 *四* 列。

### 如何修复该错误

要解决此错误并修复我们的表格，我们可以：

* 通过删除条目来移除多余的列
* 在 tabular 环境选项中添加一个额外的列（例如，写成 `{c|c|c|c}`)
* 创建一个新行（新表格行）

下面是演示这些解决方案的示例：

```latex
\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}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Options+for+correcting+a+tablular+error\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%2A%7BRemoving+the+extra+column+entry%7D%0A%0A%5Cbegin%7Bcenter%7D%0A%5Cbegin%7Btabular%7D%7Bc%7Cc%7Cc%7D%0A+++1+%26+2+%26+3%5C%5C%0A+++5+%26+6+%26+7%5C%5C%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%0A%5Csection%2A%7BAdding+an+extra+column+to+the+tabular%7D%0A%0A%5Cbegin%7Bcenter%7D%0A%5Cbegin%7Btabular%7D%7Bc%7Cc%7Cc%7Cc%7D%0A+++1+%26+2+%26+3+%26+4%5C%5C%0A+++5+%26+6+%26+7%5C%5C%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%0A%5Csection%2A%7BCreating+a+new+line+%28new+table+row%29%7D%0A%0A%5Cbegin%7Bcenter%7D%0A%5Cbegin%7Btabular%7D%7Bc%7Cc%7Cc%7D%0A+++1+%26+2+%26+3+%5C%5C%0A+++4+%26+++%26+++%5C%5C%0A+++5+%26+6+%26+7+%5C%5C%0A%5Cend%7Btabular%7D%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D)

此示例生成如下输出：

![修复 tabular 错误](/files/56d73d0420b821ddfdd834f6915e0228f1d91e26)

## 由数学环境引起的错误

数学排版通常需要对数学元素进行对齐，这可以通过诸如 `array`, `矩阵`等环境来实现。由于某些数学环境使用表格来完成对齐，因此它们可能会触发“extra alignment tab”错误，如下面的示例所示。

### array 环境

如果 array 行中使用的对齐制表符数量超过了 array 列数，LaTeX 就会生成错误。下面是一个使用三列 array，但第一行尝试使用四列的示例：

```latex
\[
\begin{array}{lcl}
g(x) & = & (x+2)^2 & = (x+2)(x+2)\\ % This row triggers the error
& = & x^2+4x+4\\
\end{array}
\]
```

[打开此 **会产生错误的** Overleaf 中的示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=An+array+with+too+many+alignment+characters\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5C%5B%0A%5Cbegin%7Barray%7D%7Blcl%7D%0Ag%28x%29+%26+%3D+%26+%28x%2B2%29%5E2+%26+%3D+%28x%2B2%29%28x%2B2%29%5C%5C+%25+This+row+triggers+the+error%0A%26+%3D+%26+x%5E2%2B4x%2B4%5C%5C%0A%5Cend%7Barray%7D%0A%5C%5D%0A%5Cend%7Bdocument%7D)

此示例会生成以下错误消息：

![显示由于制表符过多而导致的 LaTeX array 错误的图像](/files/32ca9a49b465d59a74de6052e241b91cce70be3a)

并排版出这个 array：

$$\begin{array}{lcl} g(x) & = & (x+2)^2 \ =(x+2)(x+2) \ & = & x^2+4x+4\ \end{array}$$

要更正此错误，请将 array 重写如下：

```latex
\[
\begin{array}{lcl}
g(x) & = & (x+2)^2 \\
& = & (x+2)(x+2) \\
& = & x^2+4x+4\\
\end{array}
\]
```

[打开此 **已更正** Overleaf 中的示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Corrected+version+of+the+array+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5C%5B%0A%5Cbegin%7Barray%7D%7Blcl%7D%0Ag%28x%29+%26+%3D+%26+%28x%2B2%29%5E2+%5C%5C%0A%26+%3D+%26+%28x%2B2%29%28x%2B2%29+%5C%5C%0A%26+%3D+%26+x%5E2%2B4x%2B4%5C%5C%0A%5Cend%7Barray%7D%0A%5C%5D%0A%5Cend%7Bdocument%7D)

更正后的 array 会生成如下结果：

$$\begin{array}{lcl} g(x) & = & (x+2)^2 \ & = & (x+2)(x+2) \ & = & x^2+4x+4\ \end{array}$$

### amsmath 的矩阵环境

该 `amsmath` package 提供了许多用于排版矩阵的环境，包括 `矩阵`, `pmatrix`, `bmatrix`, `Bmatrix`, `vmatrix`，以及 `Vmatrix`.

下面的 `pmatrix` 示例尝试使用 12 列，但会生成错误，因为 `amsmath` 在排版矩阵中设置了默认的最大 10 列。

```latex
\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}
```

[打开此 **会产生错误的** Overleaf 中的示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=A+pmatrix+with+too+many+columns\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D+%25+To+access+the+matrix+environment%0A%5Cbegin%7Bdocument%7D%0A%5C%5B%0A%5Cbegin%7Bpmatrix%7D%0Aa_%7B1%2C1%7D+%26+a_%7B1%2C2%7D+%26+a_%7B1%2C3%7D+%26+a_%7B1%2C4%7D+%26+a_%7B1%2C5%7D+%26+a_%7B1%2C6%7D+%26+a_%7B1%2C7%7D+%26+a_%7B1%2C8%7D+%26+a_%7B1%2C9%7D+%26+a_%7B1%2C10%7D+%26+a_%7B1%2C11%7D+%26+a_%7B1%2C12%7D+%5C%5C%0A%5Cend%7Bpmatrix%7D%0A%5C%5D%0A%5Cend%7Bdocument%7D)

要修复该错误，请将列最大值改为 12，写作 `\setcounter{MaxMatrixCols}{12}`，或您选择的任何值。

```latex
\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}
```

[打开此 **已更正** Overleaf 中的示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=A+pmatrix+with+12+columns\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bamsmath%7D+%25+To+access+the+pmatrix+environment%0A%5Csetcounter%7BMaxMatrixCols%7D%7B12%7D%0A%5Cbegin%7Bdocument%7D%0A%5C%5B%0A%5Cbegin%7Bpmatrix%7D%0Aa_%7B1%2C1%7D+%26+a_%7B1%2C2%7D+%26+a_%7B1%2C3%7D+%26+a_%7B1%2C4%7D+%26+a_%7B1%2C5%7D+%26+a_%7B1%2C6%7D+%26+a_%7B1%2C7%7D+%26+a_%7B1%2C8%7D+%26+a_%7B1%2C9%7D+%26+a_%7B1%2C10%7D+%26+a_%7B1%2C11%7D+%26+a_%7B1%2C12%7D+%5C%5C%0A%5Cend%7Bpmatrix%7D%0A%5C%5D%0A%5Cend%7Bdocument%7D)

更正后的示例会生成如下矩阵：

$$\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}$$

## 关于 \cr 命令的简短说明

LaTeX 通过将意外的对齐字符替换为一个名为 `\cr`的基本命令来处理该问题，而该命令是 LaTeX 内部机制中用于结束表格行的核心部分。虽然用户使用 LaTeX `\\` 宏来表示表格行的结束，但实际上执行的是 `\cr` 命令，它会在 `\\` 宏被处理时在后台终止该行。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/latex/zh-cn/latex-cuo-wu/07-extra-alignment-tab-has-been-changed-to-cr.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
