> 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/vi/loi-latex/07-extra-alignment-tab-has-been-changed-to-cr.md).

# Tab căn lề thừa đã được đổi thành \cr

Lỗi này xảy ra khi LaTeX dàn trang một bảng và phát hiện một ký tự căn chỉnh (`&`) ở vị trí mà nó không mong đợi. LaTeX dùng các ký tự căn chỉnh để tách các cột của bảng và sẽ [phàn nàn](#a-short-note-on-the-cr-command) nếu một bảng cố gắng dùng nhiều cột hơn dự kiến.

## Lỗi do môi trường tabular gây ra

Môi trường tabular là một nguồn phổ biến của lỗi này, như được minh họa ở ví dụ tiếp theo. Ở đây, chúng ta đã viết `{c|c|c}` để chỉ định một bảng có ba cột (căn giữa), nghĩa là mỗi hàng bảng phải chứa ba ô.

```latex
\begin{tabular}{c|c|c} % Chỉ định 3 cột căn giữa
   1 & 2 & 3 & 4\\ % LỖI: Dùng 4 cột, không phải 3
   5 & 6 & 7\\
\end{tabular}
```

[Mở **gây lỗi** ví dụ này trong 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)

Ví dụ của chúng ta tạo ra thông báo lỗi sau:

![Minh họa lỗi bảng LaTeX "Extra alignment tab has been changed to \cr"](/files/7a449e487203ef030a34efcd78bebdb8e7f74c8d)

và dàn trang bảng này:

![](/files/bb101ffac18fdfbf45649f2855c5a1174a0e4038)

### Giải thích lỗi

Dấu `&` trong một hàng của bảng cho biết bắt đầu của cột *lần thứ hai* ; do đó, với một bảng ba cột, LaTeX kỳ vọng sẽ thấy *hai* các ký tự căn chỉnh trước mỗi ngắt dòng (`\\`). Tuy nhiên, hàng đầu tiên của bảng chúng ta dùng *ba* các ký tự căn chỉnh khiến LaTeX bối rối, làm nó đổi ký tự căn chỉnh bất ngờ thành [`\cr` lệnh](#a-short-note-on-the-cr-command)—một nỗ lực nhằm giảm số cột xuống còn ba. Lưu ý rằng việc dùng *ba* các ký tự căn chỉnh đòi hỏi *bốn* các cột.

### Cách sửa lỗi

Để giải quyết lỗi này và sửa bảng của chúng ta, ta có thể:

* xóa cột thừa bằng cách xóa mục
* thêm một cột nữa vào tùy chọn của môi trường tabular (ví dụ, viết `{c|c|c|c}`)
* tạo một dòng mới (hàng bảng mới)

Dưới đây là ví dụ minh họa từng cách giải quyết này:

```latex
\section*{Xóa mục cột thừa}

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

\section*{Thêm một cột nữa vào tabular}

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

\section*{Tạo một dòng mới (hàng bảng mới)}

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

[Mở ví dụ này trong 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)

Ví dụ này tạo ra kết quả sau:

![Sửa lỗi tabular](/files/9c802f5ccd8ff86dbb726215ead468ec9ab800ff)

## Lỗi do các môi trường toán học gây ra

Dàn trang toán học thường đòi hỏi sự căn chỉnh các phần tử toán học, điều này được thực hiện bằng các môi trường như `array`, `ma trận`, và một số môi trường khác. Một số môi trường toán học có thể gây ra lỗi tab căn chỉnh thừa vì chúng dùng một bảng để thực hiện việc căn chỉnh, như được minh họa trong các ví dụ sau.

### Môi trường array

LaTeX sẽ tạo ra lỗi nếu số tab căn chỉnh dùng trong một hàng array vượt quá số cột của array. Đây là ví dụ dùng một array có ba cột nhưng hàng đầu tiên cố dùng bốn cột:

```latex
\[
\begin{array}{lcl}
g(x) & = & (x+2)^2 & = (x+2)(x+2)\\ % Hàng này kích hoạt lỗi
& = & x^2+4x+4\\
\end{array}
\]
```

[Mở **gây lỗi** ví dụ này trong 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)

Ví dụ này tạo ra thông báo lỗi sau:

![Hình minh họa lỗi trong mảng LaTeX do quá nhiều ký tự tab](/files/0ba837b840688a97d5ed785c839dd6caca6a5804)

và dàn trang mảng này:

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

Để sửa lỗi này, hãy viết lại mảng như sau:

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

[Mở **đã sửa** ví dụ này trong 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)

Mảng đã sửa tạo ra kết quả sau:

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

### Các môi trường ma trận của amsmath

Tính năng `amsmath` gói cung cấp nhiều môi trường để dàn trang ma trận, bao gồm `ma trận`, `pmatrix`, `bmatrix`, `Bmatrix`, `vmatrix`, và `Vmatrix`.

Ví dụ sau `pmatrix` cố dùng 12 cột nhưng tạo ra lỗi vì `amsmath` đặt giới hạn tối đa mặc định là 10 cột trong các ma trận được dàn trang.

```latex
\documentclass{article}
\usepackage{amsmath} % Để truy cập môi trường ma trận
\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}
```

[Mở **gây lỗi** ví dụ này trong 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)

Để sửa lỗi, hãy đổi số cột tối đa thành 12 bằng cách viết `\setcounter{MaxMatrixCols}{12}`, hoặc bất kỳ giá trị nào bạn muốn.

```latex
\documentclass{article}
\usepackage{amsmath} % Để truy cập môi trường 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}
```

[Mở **đã sửa** ví dụ này trong 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)

Ví dụ đã sửa tạo ra ma trận sau:

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

## Một ghi chú ngắn về lệnh \cr

LaTeX giải quyết vấn đề của một ký tự căn chỉnh không mong đợi bằng cách thay thế nó bằng một lệnh cơ bản được gọi là `\cr`, vốn là một phần thiết yếu trong cơ chế nội bộ của LaTeX để kết thúc một hàng bảng. Mặc dù người dùng dùng macro LaTeX `\\` để chỉ ra kết thúc của một hàng bảng, nhưng thực ra đó là `\cr` lệnh được thực thi ở hậu trường để kết thúc hàng khi `\\` macro được xử lý.


---

# 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/vi/loi-latex/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.
