> For the complete documentation index, see [llms.txt](https://overleaf-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://overleaf-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} % 指定 3 个居中列
   1 & 2 & 3 & 4\\ % 错误：使用了 4 列，而不是 3 列
   5 & 6 & 7\\
\end{tabular}
```

[在 Overleaf 中打开此 **会产生错误的** 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*{移除多余的列条目}

\begin{center}
\begin{tabular}{c|c|c}
   1 & 2 & 3\\
   5 & 6 & 7\\
\end{tabular}
\end{center}

\section*{在 tabular 中添加一列}

\begin{center}
\begin{tabular}{c|c|c|c}
   1 & 2 & 3 & 4\\
   5 & 6 & 7\\
\end{tabular}
\end{center}

\section*{创建新的一行（新的表格行）}

\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)\\ % 此行触发错误
& = & x^2+4x+4\\
\end{array}
\]
```

[在 Overleaf 中打开此 **会产生错误的** 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 中打开此 **已更正** 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` 宏包提供了许多用于排版矩阵的环境，包括 `矩阵`, `pmatrix`, `bmatrix`, `Bmatrix`, `vmatrix`以及 `Vmatrix`.

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

```latex
\documentclass{article}
\usepackage{amsmath} % 用于访问矩阵环境
\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 中打开此 **会产生错误的** 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} % 用于访问 pmatrix 环境
\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 中打开此 **已更正** 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://overleaf-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.
