> 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/dinh-dang/10-counters.md).

# Bộ đếm

## Giới thiệu về bộ đếm trong LaTeX

Dàn trang dựa trên LaTeX là một dạng lập trình chuyên biệt: bạn đang sử dụng một ngôn ngữ dàn trang (các lệnh LaTeX) để cung cấp “chỉ dẫn”, từ đó tạo ra đầu ra: tài liệu LaTeX đã biên dịch ở dạng tệp PDF. Giống như mọi nỗ lực lập trình khác, rất có thể bạn sẽ cần LaTeX tạm thời lưu trữ các giá trị nguyên để dùng lại sau trong tài liệu (mã) của mình—bạn có thể muốn:

* dàn trang các số nguyên đã lưu đó trong tài liệu của bạn
* cung cấp đánh số tự động cho một số phần tử của tài liệu
* dùng chúng làm biến để điều khiển mã có điều kiện (hoặc vòng lặp)
* thay đổi và cập nhật giá trị của chúng bằng cách tăng/giảm theo một giá trị cố định
* đặt lại chúng về những giá trị hoàn toàn khác

Những hoạt động xử lý số nguyên như vậy cực kỳ phổ biến trong các ngôn ngữ lập trình “thông thường” như Javascript, C, Lua hoặc bất kỳ ngôn ngữ nào khác mà bạn chọn, nơi bạn thường khai báo (tạo tên cho) một biến (để chứa một số nguyên) rồi gán cho nó một giá trị. Ngôn ngữ dàn trang LaTeX cung cấp những khả năng tương tự, dù được triển khai theo một cách khá khác, như chúng ta sẽ tìm hiểu bên dưới.

Về cơ bản, một bộ đếm LaTeX là tên của một “biến LaTeX” dùng để lưu trữ các giá trị nguyên, có thể dùng cho các tác vụ được liệt kê ở trên, và còn nhiều việc khác nữa. Bản thân LaTeX sử dụng rất nhiều bộ đếm nội bộ để đánh số trang, mục, bảng, hình, danh sách gạch đầu dòng/đánh số, v.v. Bài viết này giải thích cách truy cập và sửa đổi các bộ đếm đó cũng như cách tạo và sử dụng các bộ đếm mới.

## Các lệnh LaTeX để làm việc với bộ đếm

Dưới đây là danh sách các lệnh bộ đếm của LaTeX, kèm mô tả ở các phần sau.

Tạo và tăng bộ đếm:

* [`\newcounter{somecounter}[anothercounter]`](#newcountersomecounteranothercounter)
* [`\setcounter{somecounter}{number}`](#setcountersomecounternumber)
* [`\addtocounter{somecounter}{number}`](#addtocountersomecounternumber)
* [`\stepcounter{somecounter}`](#stepcountersomecounter)
* [`\refstepcounter{somecounter}`](#refstepcountersomecounter)

Truy cập và in giá trị bộ đếm:

* [`\arabic{somecounter}`](#arabicsomecounter)
* [`\roman{somecounter}`](#romansomecounter)
* [`\Roman{somecounter}`](#romanoutput)
* [`\alph{somecounter}`](#alphsomecounter)
* [`\Alph{somecounter}`](#alphoutput)
* [`\fnsymbol{somecounter}`](#fnsymbolsomecounter)
* [`\value{somecounter}`](#valuesomecounter)

Các lệnh bộ đếm khác:

* [`\counterwithin{somecounter}{anothercounter}`](#counterwithinsomecounteranothercounter)
* [`\counterwithout{somecounter}{anothercounter}`](#counterwithoutsomecounteranothercounter)

### Tạo và tăng bộ đếm

#### \newcounter{somecounter}\[anothercounter]

Được dùng để định nghĩa một bộ đếm mới. Đối số thứ hai, được đặt trong `[]`, là tùy chọn nhưng khi được dùng thì nó định nghĩa `*somecounter*` là một bộ đếm mới, được đặt lại khi `*anothercounter*` được tăng. `\newcounter` thường được dùng ở dạng đơn giản hơn là `\newcounter{*somecounter*}` sẽ tạo ra `*somecounter*` và khởi tạo nó với giá trị 0.

* **Lưu ý**: Với mỗi bộ đếm được tạo bởi lệnh `\newcounter` này, nó *cũng* định nghĩa một lệnh có thể dùng để dàn trang giá trị của bộ đếm. Ví dụ, `\newcounter{*mycounter*}` định nghĩa một lệnh có tên `\the*mycounter*`. Một ví dụ được hiển thị trong đoạn mã LaTeX sau đây, bạn có thể mở trong Overleaf dưới dạng một tài liệu hoàn chỉnh, bằng liên kết được cung cấp:

```latex
\newcounter{mycounter}
\setcounter{mycounter}{42}
Bây giờ bạn có thể viết \verb|\themycounter| để nhận \themycounter.
```

[Mở đoạn LaTeX này trong Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+newcounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnewcounter%7Bmycounter%7D%0A%5Csetcounter%7Bmycounter%7D%7B42%7D%0AYou+can+now+write+%5Cverb%7C%5Cthemycounter%7C+to+obtain+%5Cthemycounter.%0A%5Cend%7Bdocument%7D)

Ví dụ này tạo ra $$\text{You can now write }\verb|\themycounter|\text{ to obtain 42.}$$

* **Lưu ý**: Nếu `*mycounter*` đã được định nghĩa trước đó thì LaTeX sẽ báo lỗi `c@mycounter already defined`, như được minh họa bởi ví dụ sau, bạn có thể mở trong Overleaf.

```latex
\newcounter{mycounter}
...rất nhiều mã... nhưng chúng ta quên và viết lại \verb|\newcounter{mycounter}|
\newcounter{mycounter}
```

[Mở ***mã gây lỗi*** trong Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+newcounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnewcounter%7Bmycounter%7D%0A...lots+of+code...+but+we+forget+and+write+%5Cverb%7C%5Cnewcounter%7Bmycounter%7D%7C+again%0A%5Cnewcounter%7Bmycounter%7D%0A%5Cend%7Bdocument%7D)

#### \setcounter{somecounter}{number}

Đặt `*somecounter*` để chứa giá trị `*number*`.

* **Lưu ý**: `*number*` có thể là số dương hoặc số âm.

Một ví dụ được hiển thị trong đoạn mã LaTeX sau đây, bạn có thể mở trong Overleaf dưới dạng một tài liệu hoàn chỉnh, bằng liên kết được cung cấp:

```latex
\noindent Tạo một bộ đếm mới \texttt{myvar} và gán cho nó giá trị \texttt{42}.
\vspace{10pt}

\newcounter{myvar}
\setcounter{myvar}{42}

\noindent Viết \verb|\themymar| sẽ dàn trang \texttt{\themyvar}.
\vspace{10pt}

\noindent Tiếp theo, chúng ta sẽ đổi \texttt{myvar} thành \texttt{-42} bằng cách viết \verb|\setcounter{myvar}{-42}|
\setcounter{myvar}{-42}. Bây giờ, viết \verb|\themyvar| sẽ xuất ra \texttt{\themyvar}.
```

[Mở đoạn LaTeX này trong Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+newcounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+Create+a+new+counter+%5Ctexttt%7Bmyvar%7D+and+assign+it+the+value+%5Ctexttt%7B42%7D.%0A%5Cvspace%7B10pt%7D%0A%0A%5Cnewcounter%7Bmyvar%7D%0A%5Csetcounter%7Bmyvar%7D%7B42%7D+%0A%0A%5Cnoindent+Writing+%5Cverb%7C%5Cthemymar%7C+typesets+%5Ctexttt%7B%5Cthemyvar%7D.%0A%5Cvspace%7B10pt%7D%0A%0A%5Cnoindent+Next%2C+we%27ll+change+%5Ctexttt%7Bmyvar%7D+to+%5Ctexttt%7B-42%7D%2C+writing+%5Cverb%7C%5Csetcounter%7Bmyvar%7D%7B-42%7D%7C%0A%5Csetcounter%7Bmyvar%7D%7B-42%7D.+Now%2C+writing+%5Cverb%7C%5Cthemyvar%7C+outputs+%5Ctexttt%7B%5Cthemyvar%7D.%0A%5Cend%7Bdocument%7D)

#### \addtocounter{somecounter}{number}

Tăng bộ đếm `*somecounter*` lên `*number*`.

* **Lưu ý**: `*number*` có thể là số dương, để tăng giá trị bộ đếm, hoặc số âm để giảm nó. Ví dụ:

```latex
\addtocounter{somecounter}{-1} % giảm somecounter đi 1
```

Một ví dụ được hiển thị trong đoạn mã LaTeX sau đây, bạn có thể mở trong Overleaf dưới dạng một tài liệu hoàn chỉnh, bằng liên kết được cung cấp:

```latex
\noindent Tạo một bộ đếm mới \texttt{myvar} và gán cho nó giá trị \texttt{42}.
\vspace{10pt}

\newcounter{myvar}
\setcounter{myvar}{42}

\noindent Viết \verb|\themymar| sẽ dàn trang \texttt{\themyvar}.
\vspace{10pt}

\noindent Tiếp theo, chúng ta sẽ đổi \texttt{myvar} thành \texttt{142} bằng cách viết \verb|\addtocounter{myvar}{100}|\addtocounter{myvar}{100}. Bây giờ, viết \verb|\themyvar| sẽ xuất ra \texttt{\themyvar}.
```

[Mở đoạn LaTeX này trong Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+addtocounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+Create+a+new+counter+%5Ctexttt%7Bmyvar%7D+and+assign+it+the+value+%5Ctexttt%7B42%7D.%0A%5Cvspace%7B10pt%7D%0A%0A%5Cnewcounter%7Bmyvar%7D%0A%5Csetcounter%7Bmyvar%7D%7B42%7D+%0A%0A%5Cnoindent+Writing+%5Cverb%7C%5Cthemymar%7C+typesets+%5Ctexttt%7B%5Cthemyvar%7D.%0A%5Cvspace%7B10pt%7D%0A%0A%5Cnoindent+Next%2C+we%E2%80%99ll+change+%5Ctexttt%7Bmyvar%7D+to+%5Ctexttt%7B142%7D+by+writing+%5Cverb%7C%5Caddtocounter%7Bmyvar%7D%7B100%7D%7C%5Caddtocounter%7Bmyvar%7D%7B100%7D.+Now%2C+writing+%5Cverb%7C%5Cthemyvar%7C+outputs+%5Ctexttt%7B%5Cthemyvar%7D.%0A%5Cend%7Bdocument%7D)

#### \stepcounter{somecounter}

Tăng `*somecounter*` lên 1. Một ví dụ được hiển thị trong đoạn mã LaTeX sau đây, bạn có thể mở trong Overleaf dưới dạng một tài liệu hoàn chỉnh, bằng liên kết được cung cấp:

```latex
Nếu chúng ta tạo một bộ đếm mới bằng cách viết \verb|\newcounter{mycounter}|
\newcounter{mycounter} thì bộ đếm \texttt{mycounter} được tạo ra và
được khởi tạo bằng 0, như bạn có thể thấy nếu viết \verb|\themycounter|:
\texttt{mycounter} hiện đang lưu: \themycounter.

Nếu bây giờ chúng ta viết \verb|\stepcounter{mycounter}|\stepcounter{mycounter} thì
\verb|\themycounter| bây giờ chứa giá trị \themycounter.
```

[Mở đoạn LaTeX này trong Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+stepcounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0AIf+we+create+a+new+counter+by+writing+%5Cverb%7C%5Cnewcounter%7Bmycounter%7D%7C%0A%5Cnewcounter%7Bmycounter%7D+then+the+counter+%5Ctexttt%7Bmycounter%7D+is+created+and+%0Ainitialized+to+zero%2C+as+you+can+see+if+you+write+%5Cverb%7C%5Cthemycounter%7C%3A%0A%5Ctexttt%7Bmycounter%7D+currently+stores%3A+%5Cthemycounter.+%0A%0AIf+we+now+write+%5Cverb%7C%5Cstepcounter%7Bmycounter%7D%7C%5Cstepcounter%7Bmycounter%7D+then+%0A%5Cverb%7C%5Cthemycounter%7C+now+contains+the+value+%5Cthemycounter.%0A%5Cend%7Bdocument%7D)

#### \refstepcounter{somecounter}

Tăng `*somecounter*` lên 1 và làm cho nó hiển thị được đối với cơ chế tham chiếu, đồng thời đặt giá trị để bạn có thể dùng `\label` sau đó.

**Ví dụ dùng \refstepcounter**

Ví dụ sau sử dụng `\refstepcounter` để tạo một bộ đếm mới cho một `ví dụ` môi trường và dùng `\label` và `\ref` để minh họa việc tham chiếu bằng `ví dụ` biến bộ đếm.

```latex
\documentclass{article}

\newcounter{example}[section]
\newenvironment{example}[1][]{\refstepcounter{example}\par\medskip
   \noindent\textbf{Ví dụ~\theexample. #1} \rmfamily}{\medskip}

\begin{document}
\section{Ba ví dụ}
\begin{example}
Tạo một nhãn trong ví dụ đầu tiên này \verb|\label{ex:1}|\label{ex:1}. Đây là ví dụ đầu tiên. Bộ đếm \texttt{example} sẽ được đặt lại ở đầu mỗi \verb|\section| mới của tài liệu.
\end{example}

\begin{example}
Và đây là một ví dụ đánh số khác. Tạo một nhãn thứ hai \verb|\label{ex:2}|\label{ex:2} để sau này tham chiếu đến ví dụ này. Trong Ví dụ \ref{ex:1} chúng ta đọc... điều gì đó.
\end{example}

\begin{example}
Và đây là một ví dụ đánh số khác: dùng \verb|\theexample| để dàn trang số hiện đang được gán cho bộ đếm \texttt{example}: đó là  \theexample.
\end{example}

\section{Một mục khác}
Chúng ta vừa bắt đầu một mục mới, nghĩa là bộ đếm \texttt{example} đã được đặt thành \theexample.
Chúng ta sẽ tham chiếu các ví dụ từ phần trước (Ví dụ \ref{ex:1} và \ref{ex:2}). Đây chỉ là một mục giả, không có mục đích gì ngoài việc chứa văn bản. Bộ đếm \texttt{section} cho mục này có thể được dàn trang bằng \verb|\thesection|: hiện nó được gán giá trị \thesection.

\begin{example}
Đây là ví dụ đầu tiên trong mục này: bộ đếm \texttt{example} đã được tăng và hiện được đặt thành \theexample.
\end{example}
\end{document}
```

[Mở `\refstepcounter` ví dụ này trong Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=An+example+using+refstepcounter\&snip=%5Cdocumentclass%7Barticle%7D%0A%0A%5Cnewcounter%7Bexample%7D%5Bsection%5D%0A%5Cnewenvironment%7Bexample%7D%5B1%5D%5B%5D%7B%5Crefstepcounter%7Bexample%7D%5Cpar%5Cmedskip%0A+++%5Cnoindent%5Ctextbf%7BExample%7E%5Ctheexample.+%231%7D+%5Crmfamily%7D%7B%5Cmedskip%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BThree+examples%7D%0A%5Cbegin%7Bexample%7D%0ACreate+a+label+in+this+first+example+%5Cverb%7C%5Clabel%7Bex%3A1%7D%7C%5Clabel%7Bex%3A1%7D.+This+is+the+first+example.+The+%5Ctexttt%7Bexample%7D+counter+will+be+reset+at+the+start+of+each+new+each+document+%5Cverb%7C%5Csection%7C.%0A%5Cend%7Bexample%7D%0A%0A%5Cbegin%7Bexample%7D%0AAnd+here%27s+another+numbered+example.+Create+a+second+%5Cverb%7C%5Clabel%7Bex%3A2%7D%7C%5Clabel%7Bex%3A2%7D+to+later+reference+this+one.+In+Example+%5Cref%7Bex%3A1%7D+we+read...+something.+%0A%5Cend%7Bexample%7D%0A%0A%5Cbegin%7Bexample%7D%0AAnd+here%27s+another+numbered+example%3A+use+%5Cverb%7C%5Ctheexample%7C+to+typeset+the+number+currently+assigned+to+the+%5Ctexttt%7Bexample%7D+counter%3A+it+is++%5Ctheexample.%0A%5Cend%7Bexample%7D%0A%0A%5Csection%7BAnother+section%7D%0AWe%27ve+just+started+a+new+section+meaning+that+the++%5Ctexttt%7Bexample%7D+counter+has+been+set+to+%5Ctheexample.++%0AWe%27ll+reference+examples+from+the+previous+section+%28Examples+%5Cref%7Bex%3A1%7D+and+%5Cref%7Bex%3A2%7D%29.++This+is+a+dummy+section+with+no+purpose+whatsoever+but+to+contain+text.+The+%5Ctexttt%7Bsection%7D+counter+for+this+section+can+be+typeset+using+%5Cverb%7C%5Cthesection%7C%3A+it+is++currently+assigned+the+value+of+%5Cthesection.%0A%0A%5Cbegin%7Bexample%7D%0AThis+is+the+first+example+in+this+section%3A+the+%5Ctexttt%7Bexample%7D+counter+has+been+stepped+and+now+set+to+%5Ctheexample.+%0A%5Cend%7Bexample%7D%0A%5Cend%7Bdocument%7D)

**Tóm tắt mã**

Trong ví dụ này, môi trường mới `ví dụ` được định nghĩa, môi trường này có 3 lệnh dành riêng cho việc đếm:

* `\newcounter{example}[section]`: Tạo một bộ đếm mới có tên `ví dụ` sẽ được đặt lại về 0 mỗi khi `section` bộ đếm được tăng. Bạn có thể đặt bất kỳ bộ đếm nào khác thay cho `section` hoặc bỏ qua tham số nếu bạn không muốn bộ đếm của mình được đặt lại tự động.
* `\refstepcounter{example}`: Tăng `ví dụ` bộ đếm lên 1 và làm cho nó hiển thị được đối với cơ chế tham chiếu, որպեսզի bạn có thể dùng `\label` sau đó.
* `\theexample`: In ra giá trị hiện tại của bộ đếm `ví dụ`.

Để biết thêm thông tin về các môi trường do người dùng định nghĩa, xem [bài viết về định nghĩa môi trường mới](/latex/vi/cac-lenh/02-environments.md#defining-a-new-environment)

### Truy cập và in giá trị bộ đếm

Các thảo luận sau đây dựa trên mặc định của LaTeX trước khi có bất kỳ tùy chỉnh nào được áp dụng bởi các gói do người dùng nạp vào.

#### \arabic{somecounter}

Xuất ra biểu diễn của `*somecounter*` dưới dạng chữ số Ả Rập: 1, 2, 3...

#### \roman{somecounter}

Xuất ra biểu diễn của `*somecounter*` dưới dạng số La Mã viết thường: i, ii, iii...

* **Lưu ý**: Nếu `*somecounter*` $$\leq$$ `0` không tạo ra đầu ra nào. Ngoài ra, việc chuyển đổi *cực kỳ* các giá trị số nguyên lớn sang số La Mã viết thường có thể mất rất lâu để hoàn thành—và tạo ra một chuỗi dài các `m` ký tự (biểu thị số `1000`).
* **MẸO**: Nếu bạn quan tâm đến thuật toán mà TeX dùng để chuyển đổi số Ả Rập sang số La Mã, bạn có thể đọc về nó trong bài viết này về [Thuật toán cho số La Mã](https://www.hanshq.net/roman-numerals.html#tex).

#### \Roman{somecounter}

Xuất ra biểu diễn của `*somecounter*` dưới dạng số La Mã viết hoa: I, II, III...

* **Lưu ý**: Nếu `*somecounter*` $$\leq$$ `0` không tạo ra đầu ra nào. Ngoài ra, việc chuyển đổi *cực kỳ* các giá trị số nguyên lớn sang số La Mã viết hoa có thể mất rất lâu để hoàn thành—và tạo ra một chuỗi dài các `M` ký tự (biểu thị số `1000`).
* **MẸO**: Nếu bạn quan tâm đến thuật toán mà TeX dùng để chuyển đổi số Ả Rập sang số La Mã, bạn có thể đọc về nó trong bài viết này về [Thuật toán cho số La Mã](https://www.hanshq.net/roman-numerals.html#tex).

#### \alph{somecounter}

Xuất ra biểu diễn của `*somecounter*` dưới dạng chữ thường, với a=1, b=2, c=3...

* **Lưu ý**: `*somecounter*` phải nằm trong phạm vi `1` $$\leq$$ `*somecounter*` $$\leq$$ `26`, nếu không nó sẽ kích hoạt lỗi `! Lỗi LaTeX: Counter too large.`

#### \Alph{somecounter}

Xuất ra biểu diễn của `*somecounter*` dưới dạng chữ hoa với A=1, B=2, C=3...

* **Lưu ý**: `*somecounter*` phải nằm trong phạm vi `1` $$\leq$$ `*somecounter*` $$\leq$$ `26`, nếu không nó sẽ kích hoạt lỗi `! Lỗi LaTeX: Counter too large.`

#### \fnsymbol{somecounter}

Xuất ra biểu diễn của `*somecounter*` dưới dạng ký hiệu chú thích chân trang, trong đó 1 =∗, 2 =†...

* **Lưu ý**: `*somecounter*` phải nằm trong phạm vi `1` $$\leq$$ `*somecounter*` $$\leq$$ `9`, nếu không nó sẽ kích hoạt lỗi `! Lỗi LaTeX: Counter too large.`

|                             |                                      |
| --------------------------- | ------------------------------------ |
| Giá trị của `*somecounter*` | Ký tự được dàn trang bởi `\fnsymbol` |
| 1                           | \*                                   |
| 2                           | †                                    |
| 3                           | ‡                                    |
| 4                           | §                                    |
| 5                           | ¶                                    |
| 6                           | ∥                                    |
| 7                           | ∗∗                                   |
| 8                           | ††                                   |
| 9                           | ‡‡                                   |

#### Ví dụ về in giá trị bộ đếm

Ví dụ sau minh họa việc dùng các lệnh `\arabic{*somecounter*}`, `\roman{*somecounter*}`, `\Roman{*somecounter*}`, `\alph{*somecounter*}`, `\Alph{*somecounter*}`, và `\fnsymbol{*somecounter*}`.

```latex
\newcounter{somecounter}
\setcounter{somecounter}{9}
\begin{itemize}
    \item \verb|\arabic{somecounter}| dàn trang giá trị \texttt{somecounter} của \thesomecounter{} thành \arabic{somecounter}
    \item \verb|\roman{somecounter}| dàn trang giá trị \texttt{somecounter} của \thesomecounter{} thành  \roman{somecounter}
    \item \verb|\Roman{somecounter}| dàn trang giá trị \texttt{somecounter} của \thesomecounter{} thành  \Roman{somecounter}
    \item \verb|\alph{somecounter}| dàn trang giá trị \texttt{somecounter} của \thesomecounter{} thành  \alph{somecounter}
   \item \verb|\Alph{somecounter}| dàn trang giá trị \texttt{somecounter} của \thesomecounter{} thành  \Alph{somecounter}
    \item \verb|\fnsymbol{somecounter}| dàn trang giá trị \texttt{somecounter} của \thesomecounter{} thành  \fnsymbol{somecounter}
\end{itemize}
```

[Mở đoạn LaTeX này trong Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Converting+counter+values\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnewcounter%7Bsomecounter%7D%0A%5Csetcounter%7Bsomecounter%7D%7B9%7D%0A%5Cbegin%7Bitemize%7D%0A++++%5Citem+%5Cverb%7C%5Carabic%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as+%5Carabic%7Bsomecounter%7D+%0A++++%5Citem+%5Cverb%7C%5Croman%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as++%5Croman%7Bsomecounter%7D%0A++++%5Citem+%5Cverb%7C%5CRoman%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as++%5CRoman%7Bsomecounter%7D%0A++++%5Citem+%5Cverb%7C%5Calph%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as++%5Calph%7Bsomecounter%7D%0A+++%5Citem+%5Cverb%7C%5CAlph%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as++%5CAlph%7Bsomecounter%7D%0A++++%5Citem+%5Cverb%7C%5Cfnsymbol%7Bsomecounter%7D%7C+typesets+the+%5Ctexttt%7Bsomecounter%7D+value+of++%5Cthesomecounter%7B%7D+as++%5Cfnsymbol%7Bsomecounter%7D%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bdocument%7D)

Ví dụ này tạo ra đầu ra sau:

![Ví dụ về chuyển đổi bộ đếm trong LaTeX](/files/d5acca1db280cfe38bfd1ce566fc8dd5646d461e)

#### \value{somecounter}

Mục đích của lệnh này, như được mô tả trong mã nguồn LaTeX, là “Để truy cập giá trị của bộ đếm dưới dạng một số TeX”: tức là, bạn dùng `\value{somecounter}` trong những trường hợp LaTeX đang chờ xử lý một giá trị số.

**(Tùy chọn) ghi chú nền về lệnh \value**

Dễ nghĩ rằng lệnh `\value{*somecounter*}` sẽ *trực tiếp* dàn trang giá trị của `*somecounter*`, nhưng không phải vậy. Nó được thiết kế để dùng bên trong các lệnh khác nhằm truy cập giá trị của bộ đếm dưới dạng một số TeX, trái ngược với lệnh `\thesomecounter` là lệnh tạo ra dạng biểu diễn đã in của `*somecounter*`.

Trong mã nguồn LaTeX, `\value` được định nghĩa như sau:

```latex
\def\value#1{\csname c@#1\endcsname}
```

Do đó, `\value{*somecounter*}` tạo ra một thể hiện của chuỗi điều khiển nội bộ của LaTeX `\c@somecounter` chứa giá trị của bộ đếm `*somecounter*`.

**Ví dụ**

Ví dụ sau cho thấy một trường hợp sử dụng cơ bản của `\value`.

```latex
\noindent Hãy bắt đầu bằng cách khai báo hai bộ đếm mới:
\begin{verbatim}
\newcounter{first}
\newcounter{second}
\end{verbatim}

\newcounter{first}
\newcounter{second}

\noindent Sau đó, ở một thời điểm nào đó trong mã của bạn, bạn đặt giá trị của chúng:
\begin{verbatim}
\setcounter{first}{100}
\setcounter{second}{50}
\end{verbatim}

\setcounter{first}{100}
\setcounter{second}{50}
\noindent Rồi bạn viết thêm mã \LaTeX{}...\vspace{10pt}

\noindent Tại một thời điểm nào đó, chúng ta có thể muốn cộng giá trị của bộ đếm \texttt{second} vào bộ đếm \texttt{first}. Một cách để làm điều đó là dùng \verb|\value| để lấy giá trị \textit{hiện tại} đang lưu trong bộ đếm \texttt{second}:

\begin{verbatim}
\addtocounter{first}{\value{second}}
\end{verbatim}

\addtocounter{first}{\value{second}}\noindent Giá trị của \texttt{first} có thể được xuất ra bằng \verb|\thefirst|: \thefirst. Chúng ta cũng có thể viết \verb|\the\value{first}|, cách này cũng sẽ dàn trang \the\value{first}. Tuy nhiên, viết \verb|\value{first}| sẽ tạo ra lỗi \texttt{Missing number, treated as zero} vì khi đó \LaTeX{} cố gắng thực thi lệnh nội bộ \verb|\c@first|. Hãy bỏ chú thích dòng sau để tạo lỗi:
\begin{verbatim}
%\value{first}
\end{verbatim}
%\value{first}
```

[Mở đoạn mã này trong Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+the+value+command\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cnoindent+Start+by+declaring+two+new+counters%3A%0A%5Cbegin%7Bverbatim%7D%0A%5Cnewcounter%7Bfirst%7D%0A%5Cnewcounter%7Bsecond%7D++++%0A%5Cend%7Bverbatim%7D%0A%0A%5Cnewcounter%7Bfirst%7D%0A%5Cnewcounter%7Bsecond%7D%0A%0A%5Cnoindent+Sometime+later+in+your+code+you+set+their+values%3A%0A%5Cbegin%7Bverbatim%7D%0A%5Csetcounter%7Bfirst%7D%7B100%7D%0A%5Csetcounter%7Bsecond%7D%7B50%7D++++%0A%5Cend%7Bverbatim%7D%0A%0A%5Csetcounter%7Bfirst%7D%7B100%7D%0A%5Csetcounter%7Bsecond%7D%7B50%7D++%0A%5Cnoindent+Then+you+write+more+%5CLaTeX%7B%7D+code...%5Cvspace%7B10pt%7D%0A%0A%5Cnoindent+At+some+point+we+might+want+to+add+the+value+of+counter+%5Ctexttt%7Bsecond%7D+to+counter+%5Ctexttt%7Bfirst%7D.+One+way+to+do+that+is+using+%5Cverb%7C%5Cvalue%7C+to+obtain+the+%5Ctextit%7Bcurrent%7D+value+stored+in+the+%5Ctexttt%7Bsecond%7D+counter%3A%0A%0A%5Cbegin%7Bverbatim%7D%0A%5Caddtocounter%7Bfirst%7D%7B%5Cvalue%7Bsecond%7D%7D%0A%5Cend%7Bverbatim%7D%0A%0A%5Caddtocounter%7Bfirst%7D%7B%5Cvalue%7Bsecond%7D%7D%5Cnoindent+The+value+of+%5Ctexttt%7Bfirst%7D+can+be+output+by+%5Cverb%7C%5Cthefirst%7C%3A+%5Cthefirst.+We+can+also+write+%5Cverb%7C%5Cthe%5Cvalue%7Bfirst%7D%7C+which+also+typesets+%5Cthe%5Cvalue%7Bfirst%7D.+However%2C++writing+%5Cverb%7C%5Cvalue%7Bfirst%7D%7C+will+generate+the+error+%5Ctexttt%7BMissing+number%2C+treated+as+zero%7D+because+%5CLaTeX%7B%7D+then+tries+to+execute+the+internal+command+%5Cverb%7C%5Cc%40first%7C.+Uncomment+the+following+line+to+generate+the+error%3A%0A%5Cbegin%7Bverbatim%7D%0A%25%5Cvalue%7Bfirst%7D%0A%5Cend%7Bverbatim%7D%0A%25%5Cvalue%7Bfirst%7D%0A%5Cend%7Bdocument%7D)

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

![Ví dụ dùng lệnh \value](/files/5b355f6e2851ef4d0c0e172cb2bfd50f192f5636)

### Các lệnh bộ đếm khác

Ở đây chúng tôi mô tả các lệnh `\counterwithin` và `\counterwithout` có nguồn gốc từ [`chngcntr` gói](https://ctan.org/pkg/chngcntr) nhưng hiện đã được tích hợp vào chính LaTeX—xem [LaTeX News, tháng 4 năm 2018](https://www.latex-project.org/news/latex2e-news/ltnews28.pdf). Gói `chngcntr` [tài liệu gói](https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/chngcntr/chngcntr.pdf) đưa ra các nhận xét sau đây, giúp hiểu mục đích của các lệnh này:

Bật `\counterwithin`:

> Đôi khi mong muốn thay đổi một bộ đếm đã được định nghĩa bằng `\newcounter{<ctr>}` để nó hoạt động như thể nó đã được định nghĩa là `\newcounter{<ctr>}[<within>]`. Gói cung cấp lệnh `\counterwithin{<ctr>}{<within>}` để thực hiện điều đó.

Bật `\counterwithout`:

> Tương tự, lệnh `\counterwithout{<ctr>}{<within>}` thay đổi một bộ đếm đã được tạo bởi `\newcounter{<ctr>}[<within>]` để nó hoạt động như thể nó đã được tạo bởi `\newcounter{<ctr>}`.

Về cơ bản, hai lệnh này cung cấp một cách để liên kết (`\counterwithin`) hoặc tách liên kết (`\counterwithout`) hai bộ đếm sau khi chúng đã được định nghĩa.

**\counterwithin{somecounter}{anothercounter}**

Đặt lại `*somecounter*` về 0 mỗi khi `*anothercounter*` được tăng, một cơ chế liên kết hai bộ đếm. Ngoài việc tạo liên kết, lệnh này còn định nghĩa lại phần được dàn trang bởi `\the*somecounter*`thay vì xuất ra giá trị của bộ đếm `*somecounter*` nó tạo ra `<value of anothercounter>**.**<value of somecounter>`. Dạng có dấu sao (`\counterwithin*{somecounter}{anothercounter}`) không định nghĩa lại định dạng in của `*somecounter*`, như ví dụ sau minh họa—hãy chọn liên kết bên dưới đoạn mã để mở nó trong Overleaf:

```latex
\documentclass{article}
\begin{document}
\section{Một ví dụ ngắn}
\newcounter{example}
\counterwithin{example}{section}
\newcounter{exampletwo}
\counterwithin*{exampletwo}{section}
\setcounter{example}{100}
\setcounter{exampletwo}{100}
\begin{itemize}
\item \verb|\theexample| dàn trang \theexample
\item \verb|\theexampletwo| dàn trang \theexampletwo
\end{itemize}
\end{document}
```

[Mở `\counterwithin` ví dụ này trong Overleaf](https://www.overleaf.com/docs?engine=\&snip_name=Example+of+starred+version+of+counterwithin\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BA+short+example%7D%0A%5Cnewcounter%7Bexample%7D%0A%5Ccounterwithin%7Bexample%7D%7Bsection%7D%0A%5Cnewcounter%7Bexampletwo%7D%0A%5Ccounterwithin%2A%7Bexampletwo%7D%7Bsection%7D%0A%5Csetcounter%7Bexample%7D%7B100%7D%0A%5Csetcounter%7Bexampletwo%7D%7B100%7D%0A%5Cbegin%7Bitemize%7D%0A%5Citem+%5Cverb%7C%5Ctheexample%7C+typesets+%5Ctheexample%0A%5Citem+%5Cverb%7C%5Ctheexampletwo%7C+typesets+%5Ctheexampletwo%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bdocument%7D)

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

![Sử dụng lệnh \counterwithin](/files/df593845fcfba2a6e746df76144ccac8cdfecc4a)

Bạn có thể dùng `\counterwithin` với các bộ đếm chuẩn do LaTeX cung cấp, chẳng hạn như:

* `section`: được dùng bởi `\section` lệnh
* `equation` được dùng bởi `equation` môi trường

hoặc với các bộ đếm bạn đã tạo.

**Ví dụ về \counterwithin và \counterwithin\***

Đoạn mã sau cung cấp một ví dụ đầy đủ hơn về cách dùng `\counterwithin` và `\counterwithin*`; hãy chọn liên kết bên dưới đoạn mã để mở nó trong Overleaf:

```latex
\documentclass{article}
\counterwithin{equation}{section}
\newcounter{example}
\counterwithin*{example}{section}
\newenvironment{example}[1][]{%
\stepcounter{example}%
\par\vspace{5pt}\noindent
\fbox{\textbf{Ví dụ~\thesection.\theexample}}%
\hrulefill\par\vspace{10pt}\noindent\rmfamily}%
{\par\noindent\hrulefill\vrule width10pt height2pt depth2pt\par}
\begin{document}
\section{Phương trình thứ nhất}
Một đoạn văn mở đầu...
\begin{example}
\begin{equation}
    f(x)=\frac{x}{1+x^2}
\end{equation}
\end{example}

\subsection{Chi tiết hơn}
\begin{example}
Ở đây chúng ta bàn về
\begin{equation}
    f(x)=\frac{x+1}{x-1}
\end{equation}
... nhưng đừng nói gì cả
\end{example}

\subsubsection{Chi tiết hơn nữa}
\begin{example}
\begin{equation}
    f(x)=\frac{x^2}{1+x^3}
\end{equation}
\begin{equation}
    f(x+\delta x)=\frac{(x+\delta x)^2}{1+(x+\delta x)^3}
\end{equation}
\end{example}

\section{Phương trình thứ ba}
\begin{example}
Hàm sau...
\begin{equation}
    f_1(x)=\frac{x+1}{x-1}
\end{equation}
..là một hàm
\begin{equation}
    f_2(x)=\frac{x^2}{1+x^3}
\end{equation}
\begin{equation}
    f_3(x)=\frac{3+ x^2}{1-x^3}
\end{equation}
\end{example}
\end{document}
```

[Mở `\counterwithin` ví dụ này trong Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+using+counterwithin\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Ccounterwithin%7Bequation%7D%7Bsection%7D%0A%5Cnewcounter%7Bexample%7D%0A%5Ccounterwithin%2A%7Bexample%7D%7Bsection%7D%0A%5Cnewenvironment%7Bexample%7D%5B1%5D%5B%5D%7B%25%0A%5Cstepcounter%7Bexample%7D%25%0A%5Cpar%5Cvspace%7B5pt%7D%5Cnoindent%0A%5Cfbox%7B%5Ctextbf%7BExample%7E%5Cthesection.%5Ctheexample%7D%7D%25%0A%5Chrulefill%5Cpar%5Cvspace%7B10pt%7D%5Cnoindent%5Crmfamily%7D%25%0A%7B%5Cpar%5Cnoindent%5Chrulefill%5Cvrule+width10pt+height2pt+depth2pt%5Cpar%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BFirst+equation%7D%0ASome+introductory+text...%0A%5Cbegin%7Bexample%7D%0A%5Cbegin%7Bequation%7D%0A++++f%28x%29%3D%5Cfrac%7Bx%7D%7B1%2Bx%5E2%7D%0A%5Cend%7Bequation%7D%0A%5Cend%7Bexample%7D%0A%0A%5Csubsection%7BMore+detail%7D%0A%5Cbegin%7Bexample%7D%0AHere+we+discuss%0A%5Cbegin%7Bequation%7D%0A++++f%28x%29%3D%5Cfrac%7Bx%2B1%7D%7Bx-1%7D%0A%5Cend%7Bequation%7D%0A...+but+don%27t+say+anything%0A%5Cend%7Bexample%7D%0A%0A%5Csubsubsection%7BEven+more+detail%7D%0A%5Cbegin%7Bexample%7D%0A%5Cbegin%7Bequation%7D%0A++++f%28x%29%3D%5Cfrac%7Bx%5E2%7D%7B1%2Bx%5E3%7D%0A%5Cend%7Bequation%7D%0A%5Cbegin%7Bequation%7D%0A++++f%28x%2B%5Cdelta+x%29%3D%5Cfrac%7B%28x%2B%5Cdelta+x%29%5E2%7D%7B1%2B%28x%2B%5Cdelta+x%29%5E3%7D%0A%5Cend%7Bequation%7D%0A%5Cend%7Bexample%7D%0A%0A%5Csection%7BThird+equation%7D%0A%5Cbegin%7Bexample%7D%0AThe+following+function...%0A%5Cbegin%7Bequation%7D%0A++++f_1%28x%29%3D%5Cfrac%7Bx%2B1%7D%7Bx-1%7D%0A%5Cend%7Bequation%7D%0A..is+a+function%0A%5Cbegin%7Bequation%7D%0A++++f_2%28x%29%3D%5Cfrac%7Bx%5E2%7D%7B1%2Bx%5E3%7D%0A%5Cend%7Bequation%7D%0A%5Cbegin%7Bequation%7D%0A++++f_3%28x%29%3D%5Cfrac%7B3%2B+x%5E2%7D%7B1-x%5E3%7D%0A%5Cend%7Bequation%7D%0A%5Cend%7Bexample%7D%0A%5Cend%7Bdocument%7D)

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

![Sử dụng lệnh \counterwithin](/files/e208611c53bcb861f9ab7b142a5e2152164a0b7d)

**Tóm tắt mã**

* `\newcounter{example}`: Điều này tạo ra một bộ đếm mới để dùng trong môi trường của chúng ta, cũng còn được gọi là `ví dụ`
* `\counterwithin*{example}{section}`: Điều này liên kết `ví dụ` bộ đếm của chúng ta với bộ đếm `section` được dùng bên trong lệnh `\section` mỗi khi chúng ta đưa ra một lệnh `\section` lệnh `ví dụ` bộ đếm được đặt lại về 0. Lưu ý rằng chúng ta đã dùng phiên bản có dấu sao `\counterwithin*` để tránh định nghĩa lại `\theexample`
* Tiếp theo, chúng ta tạo một môi trường mới cũng có tên là `ví dụ`. Bên trong môi trường đó, chúng ta dùng `\stepcounter{example}` để tăng bộ đếm của môi trường. Cũng lưu ý rằng chúng ta viết `\textbf{Ví dụ~\thesection.\theexample}` để xuất ra **Ví dụ** `<số mục>.<số ví dụ>`

```latex
\newenvironment{example}[1][]{%
\stepcounter{example}%
\par\vspace{5pt}\noindent
\fbox{\textbf{Ví dụ~\thesection.\theexample}}%
\hrulefill\par\vspace{10pt}\noindent\rmfamily}%
{\par\noindent\hrulefill\vrule width10pt height2pt depth2pt}
```

**\counterwithout{somecounter}{anothercounter}**

`\counterwithout{*somecounter*}{*anothercounter*}` loại bỏ liên kết giữa `*somecounter*` và `*anothercounter*` để chúng độc lập. Với bất kỳ cặp bộ đếm nào, bạn có thể chuyển đổi giữa việc dùng `\counterwithout` và `\counterwithin`, như ví dụ sau cho thấy đối với các bộ đếm `ví dụ` và `section` —bạn có thể mở ví dụ này trong Overleaf bằng liên kết được cung cấp bên dưới đoạn mã.

```latex
\section{Phương trình thứ nhất}
\begin{example}
\begin{equation}
    f(x)=\frac{x}{1+x^2}
\end{equation}
\end{example}

\subsection{Phương trình thứ hai}
\begin{example}
\begin{equation}
    f(x)=\frac{x+1}{x-1}
\end{equation}
\end{example}
\vspace{6pt}\noindent Lưu ý cách bộ đếm \texttt{example} được đặt lại ở đầu Mục \ref{sec:n0}.
\section{Phương trình thứ ba}
\label{sec:n0}
\begin{example}
\begin{equation}
    f(x)=\frac{x+1}{x-1}
\end{equation}
\end{example}
\vspace{6pt}\noindent Ở đây, chúng tôi đã viết \verb|\counterwithout{example}{section}| để \texttt{example} không còn được đặt lại ở đầu mỗi mục. Ở các Mục \ref{sec:n1} và \ref{sec:n2}, bộ đếm \texttt{example} tiếp tục tăng. \counterwithout{example}{section}
\section{Phương trình thứ tư}
\label{sec:n1}
\begin{example}
\begin{equation}
    f(x)=\frac{x^2+x^3}{1+x^3}
\end{equation}
\end{example}
\section{Phương trình thứ năm}
\label{sec:n2}
\begin{example}
\begin{equation}
    f(x,k)=\frac{x^2-x^k}{1+x^3}
\end{equation}
\end{example}
```

[Mở `\counterwithout` ví dụ này trong Overleaf](<https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+using+counterwithout\&snip=\documentclass{article}&#xA;\counterwithin{equation}{section}&#xA;\newcounter{example}&#xA;\counterwithin*{example}{section}&#xA;\newenvironment{example}\[1]\[]{%&#xA;\stepcounter{example}%&#xA;\par\vspace{3pt}\noindent&#xA;\fbox{\textbf{Example~\thesection.\theexample}}%&#xA;\hrulefill\par\vspace{3pt}\noindent\rmfamily}%&#xA;{\par\noindent\hrulefill\vrule+width10pt+height2pt+depth2pt\par}&#xA;\begin{document}&#xA;\section{First+equation}&#xA;\begin{example}&#xA;\begin{equation}&#xA;++++f(x)=\frac{x}{1+x^2}&#xA;\end{equation}&#xA;\end{example}&#xA;&#xA;\subsection{Second+equation}&#xA;\begin{example}&#xA;\begin{equation}&#xA;++++f(x)=\frac{x+1}{x-1}&#xA;\end{equation}&#xA;\end{example}&#xA;\vspace{6pt}\noindent+Note+how+the+\texttt{example}+counter+is+reset+at+the+start+Section+\ref{sec:n0}.+&#xA;\section{Third+equation}&#xA;\label{sec:n0}&#xA;\begin{example}&#xA;\begin{equation}&#xA;++++f(x)=\frac{x+1}{x-1}&#xA;\end{equation}&#xA;\end{example}&#xA;\vspace{6pt}\noindent+Here,+we+wrote+\verb|\counterwithout{example}{section}|+so+that+\texttt{example}+is+no+longer+reset+at+the+start+of+a+section.+In+Sections+\ref{sec:n1}+and+\ref{sec:n2}+the+\texttt{example}+counter+keeps+increasing.+\counterwithout{example}{section}&#xA;\section{Fourth+equation}&#xA;\label{sec:n1}&#xA;\begin{example}&#xA;\begin{equation}&#xA;++++f(x)=\frac{x^2+x^3}{1+x^3}&#xA;\end{equation}&#xA;\end{example}&#xA;\section{Fifth+equation}&#xA;\label{sec:n2}&#xA;\begin{example}&#xA;\begin{equation}&#xA;++++f(x,k)=\frac{x^2-x^k}{1+x^3}&#xA;\end{equation}&#xA;\end{example}&#xA;\end{document}>)

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

![Sử dụng lệnh counterwithout](/files/391ba3b5bd5039d5731a04ac678a2597ebb626cb)

## Ví dụ

### enumerate

Tính năng `enumerate` môi trường danh sách sử dụng bốn *bộ đếm* biến theo dõi giá trị nhãn hiện tại cho mỗi cấp:

|         |                          |
| ------- | ------------------------ |
| **Cấp** | **`enumerate`** biến đếm |
| Cấp 1   | `enumi`                  |
| Cấp 2   | `enumii`                 |
| Cấp 3   | `enumiii`                |
| Cấp 4   | `enumiv`                 |

Các bộ đếm này có thể được thay đổi bằng `\setcounter` lệnh. Xem ví dụ dưới đây — đây chưa hẳn là giải pháp tốt nhất (xem [Danh sách Overleaf](/latex/vi/kien-thuc-co-ban-ve-latex/04-lists.md) bài viết để biết thêm thông tin):

```latex
Ví dụ này cho thấy một cách để thay đổi cách đánh số của danh sách; ở đây, thay đổi giá trị của bộ đếm \texttt{enumi} để bắt đầu đánh số danh sách từ 4 (nó được tăng lên bởi lệnh \verb|\item|):

\begin{enumerate}
\setcounter{enumi}{3}
\item Một mục gì đó.
\item Một mục khác.
\item Một phần tử khác.
\item Mục cuối cùng trong danh sách.
\end{enumerate}
```

[Mở ví dụ này trong Overleaf](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Modifying+an+enumerate+counter\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7BIntroduction%7D%0AThis+example+shows+one+way+to+change+the+numbering+of+a+list%3B+here%2C+changing+the+value+of+the+%5Ctexttt%7Benumi%7D+counter+to+start+the+list+numbering+at+4+%28it+is+incremented+by+the+%5Cverb%7C%5Citem%7C+command%29%3A%0A%0A%5Cbegin%7Benumerate%7D%0A%5Csetcounter%7Benumi%7D%7B3%7D%0A%5Citem+Something.%0A%5Citem+Something+else.%0A%5Citem+Another+element.%0A%5Citem+The+last+item+in+the+list.%0A%5Cend%7Benumerate%7D%0A%5Cend%7Bdocument%7D)

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

![Chỉnh sửa bộ đếm của môi trường enumerate](/files/eb381962408e5a4df72577721e06507da830e3d7)

## Các bộ đếm mặc định trong LaTeX

| Cách sử dụng               | Tên                                                                                                    |
| -------------------------- | ------------------------------------------------------------------------------------------------------ |
| Cho cấu trúc tài liệu      | <p>- phần<br>- chương<br>- mục<br>- tiểu mục<br>- tiểu mục con<br>- đoạn<br>- tiểu đoạn<br>- trang</p> |
| Cho các đối tượng nổi      | <p>- phương trình<br>- hình<br>- bảng</p>                                                              |
| Cho chú thích chân trang   | <p>- chú thích chân trang<br>- mpfootnote</p>                                                          |
| Cho `enumerate` môi trường | <p>- enumi<br>- enumii<br>- enumiii<br>- enumiv</p>                                                    |

## Đọc thêm

Để biết thêm thông tin, xem:

* [Các môi trường](/latex/vi/cac-lenh/02-environments.md)
* [Các lệnh](/latex/vi/cac-lenh/01-commands.md)
* [Danh sách](/latex/vi/kien-thuc-co-ban-ve-latex/04-lists.md)
* [Đánh số trang](/latex/vi/dinh-dang/03-page-numbering.md)
* [Các phần và chương](/latex/vi/cau-truc-tai-lieu/01-sections-and-chapters.md)
* [Biểu thức toán học](/latex/vi/toan-hoc/01-mathematical-expressions.md)
* [Chèn hình ảnh](/latex/vi/chu-de-khac/27-inserting-images.md)
* [Bảng](/latex/vi/hinh-va-bang/01-tables.md)
* [Soạn đề thi trong LaTeX](/latex/vi/theo-linh-vuc/09-typesetting-exams-in-latex.md)
* [Viết gói của riêng bạn](/latex/vi/tep-lop/03-writing-your-own-package.md)
* [Viết lớp của riêng bạn](/latex/vi/tep-lop/04-writing-your-own-class.md)
* [Phần giới thiệu về LaTeX2ε không quá ngắn](http://www.ctan.org/tex-archive/info/lshort/)


---

# 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/dinh-dang/10-counters.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.
