> 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/wen-dang-jie-gou/02-table-of-contents.md).

# 目录

在 LaTeX 文档中，目录可以自动生成，并可修改以适应特定样式，本文将介绍如何做

## 引言

创建目录很简单，命令 `\tableofcontents` 即可完成。章节、小节和章都会包含在目录中。若要手动添加条目，例如当你想要一个无编号的节时，请使用命令 `\addcontentsline` 如下例所示：

```latex
\documentclass{article}
\usepackage{blindtext}
\usepackage{titlesec}
\title{章节与分节}
\author{Gubert Farnsworth}
\date{ }
\begin{document}

\maketitle

\tableofcontents

\section{引言}

这是第一节。

\blindtext

\addcontentsline{toc}{section}{未编号节}
\section*{未编号节}

\blindtext

\section{第二节}

\blindtext
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Table+of+contents+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bblindtext%7D%0A%5Cusepackage%7Btitlesec%7D%0A%5Ctitle%7BSections+and+Chapters%7D%0A%5Cauthor%7BGubert+Farnsworth%7D%0A%5Cdate%7B+%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cmaketitle%0A%0A%5Ctableofcontents%0A%0A%5Csection%7BIntroduction%7D%0A%0AThis+is+the+first+section.%0A%0A%5Cblindtext%0A%0A%5Caddcontentsline%7Btoc%7D%7Bsection%7D%7BUnnumbered+Section%7D%0A%5Csection%2A%7BUnnumbered+Section%7D%0A%0A%5Cblindtext%0A%0A%5Csection%7BSecond+Section%7D%0A%0A%5Cblindtext%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![LaTeX 生成的目录示例](/files/7f9d2e8dd471f3a5fa7a39b94a7379189ae1f869)

## 更改目录标题

目录的默认标题是 **目录**；它可以根据需要更改为任意标题，如下例所示：

```latex
\documentclass{article}
\title{章节与分节}
\author{Gubert Farnsworth}
\date{ }
\renewcommand*\contentsname{摘要}
\begin{document}
\maketitle
\tableofcontents
\section{引言}

这是第一节。

Lorem  ipsum  dolor  sit  amet,  consectetuer  adipiscing
elit.   Etiam  lobortisfacilisis sem.  Nullam nec mi et
neque pharetra sollicitudin.  Praesent imperdietmi nec ante.
Donec ullamcorper, felis non sodales...

\addcontentsline{toc}{section}{未编号节}
\section*{未编号节}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra
sollicitudin.  Praesent imperdiet mi necante...

\section{第二节}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem.  Nullam nec mi et neque pharetra
sollicitudin.  Praesent imperdiet mi necante...
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=How+to+change+title+of+table+of+contents\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Ctitle%7BSections+and+Chapters%7D%0A%5Cauthor%7BGubert+Farnsworth%7D%0A%5Cdate%7B+%7D%0A%5Crenewcommand%2A%5Ccontentsname%7BSummary%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A%5Ctableofcontents%0A%5Csection%7BIntroduction%7D%0A+++%0AThis+is+the+first+section.%0A++++++%0ALorem++ipsum++dolor++sit++amet%2C++consectetuer++adipiscing++%0Aelit.+++Etiam++lobortisfacilisis+sem.++Nullam+nec+mi+et+%0Aneque+pharetra+sollicitudin.++Praesent+imperdietmi+nec+ante.+%0ADonec+ullamcorper%2C+felis+non+sodales...%0A+++++++%0A%5Caddcontentsline%7Btoc%7D%7Bsection%7D%7BUnnumbered+Section%7D%0A%5Csection%2A%7BUnnumbered+Section%7D%0A%0ALorem+ipsum+dolor+sit+amet%2C+consectetuer+adipiscing+elit.++%0AEtiam+lobortis+facilisissem.++Nullam+nec+mi+et+neque+pharetra+%0Asollicitudin.++Praesent+imperdiet+mi+necante...%0A%0A%5Csection%7BSecond+Section%7D%0A+++++++%0ALorem+ipsum+dolor+sit+amet%2C+consectetuer+adipiscing+elit.++%0AEtiam+lobortis+facilisissem.++Nullam+nec+mi+et+neque+pharetra+%0Asollicitudin.++Praesent+imperdiet+mi+necante...%0A%5Cend%7Bdocument%7D)

此示例生成以下输出：

![在 LaTeX 中更改目录名称](/files/7a4e39fd910dbab2f8936ef894fafac456aa9df3)

这一行 `\renewcommand*\contentsname{摘要}` 将写入“摘要”而不是默认值。如果你正在使用宏包 *babel* 用于 [国际语言支持](/latex/zh-cn/yu-yan/03-international-language-support.md)，上述命令必须放在以下命令的大括号内：

```latex
\addto\captionsenglish{ }
```

在 `\captionenglish` 中，写入你在 babel 中设置的语言名称。

## 进一步阅读

更多信息请参见：

* [在 LaTeX 中创建文档](/latex/zh-cn/latex-ji-chu/01-learn-latex-in-30-minutes.md)
* [加粗、斜体和下划线](/latex/zh-cn/latex-ji-chu/03-bold-italics-and-underlining.md)
* [国际语言支持](/latex/zh-cn/yu-yan/03-international-language-support.md)
* [章节和公式的交叉引用](/latex/zh-cn/wen-dang-jie-gou/03-cross-referencing-sections-equations-and-floats.md)
* [索引](/latex/zh-cn/wen-dang-jie-gou/04-indices.md)
* [术语表](/latex/zh-cn/wen-dang-jie-gou/05-glossaries.md)
* [大型项目中的管理](/latex/zh-cn/wen-dang-jie-gou/07-management-in-a-large-project.md)
* [多文件 LaTeX 项目](/latex/zh-cn/wen-dang-jie-gou/08-multi-file-latex-projects.md)
* [超链接](/latex/zh-cn/wen-dang-jie-gou/09-hyperlinks.md)
* [页码编号](/latex/zh-cn/ge-shi-hua/03-page-numbering.md)
* [单面和双面文档](/latex/zh-cn/ge-shi-hua/08-single-sided-and-double-sided-documents.md)
* [多栏](/latex/zh-cn/ge-shi-hua/09-multiple-columns.md)
* [计数器](/latex/zh-cn/ge-shi-hua/10-counters.md)
* [字体大小、字体族和样式](/latex/zh-cn/zi-ti/01-font-sizes-families-and-styles.md)


---

# 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/wen-dang-jie-gou/02-table-of-contents.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.
