> 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-tw/wen-jian-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/d2c59bb67caeae59b5367bcecc04b2d2f27585f6)

## 變更目錄標題

目錄的預設標題是 **內容**；它可以依照你的需求改成任何名稱，如下例所示：

```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/10b35807f688bee82526d2634ed427d0cc04e680)

這一行 `\renewcommand*\contentsname{摘要}` 會寫入「摘要」而不是預設值。若你使用套件 *babel* 用於 [國際語言支援](/latex/zh-tw/yu-yan/03-international-language-support.md)，前述指令必須放在

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

的括號內，而不是英文中的 `\captionenglish` 請改寫成你在 babel 中設定的語言名稱。

## 延伸閱讀

更多資訊請參見：

* [在 LaTeX 中建立文件](/latex/zh-tw/latex-ji-chu/01-learn-latex-in-30-minutes.md)
* [粗體、斜體與底線](/latex/zh-tw/latex-ji-chu/03-bold-italics-and-underlining.md)
* [國際語言支援](/latex/zh-tw/yu-yan/03-international-language-support.md)
* [章節與方程式的交叉引用](/latex/zh-tw/wen-jian-jie-gou/03-cross-referencing-sections-equations-and-floats.md)
* [索引](/latex/zh-tw/wen-jian-jie-gou/04-indices.md)
* [詞彙表](/latex/zh-tw/wen-jian-jie-gou/05-glossaries.md)
* [大型專案中的管理](/latex/zh-tw/wen-jian-jie-gou/07-management-in-a-large-project.md)
* [多檔案 LaTeX 專案](/latex/zh-tw/wen-jian-jie-gou/08-multi-file-latex-projects.md)
* [超連結](/latex/zh-tw/wen-jian-jie-gou/09-hyperlinks.md)
* [頁碼編號](/latex/zh-tw/ge-shi-hua/03-page-numbering.md)
* [單面與雙面文件](/latex/zh-tw/ge-shi-hua/08-single-sided-and-double-sided-documents.md)
* [多欄](/latex/zh-tw/ge-shi-hua/09-multiple-columns.md)
* [計數器](/latex/zh-tw/ge-shi-hua/10-counters.md)
* [字型大小、字族與樣式](/latex/zh-tw/zi-xing/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-tw/wen-jian-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.
