How to generate a table of contents for a LaTeX paper: Instructions and FAQs

Key points of this article

Key points of this article

  • Write \tableofcontents at the beginning of the text to generate a table of contents, with entries coming from heading commands such as section and subsection.
  • Table of contents usually need to be compiled twice to display the complete entries and page numbers, and it is common for the first result to be empty or have question marks.
  • If you do not need a number and do not want to enter the title of the directory, use the command with an asterisk; when you need to enter the directory, manually fill in the entries.
  • Chinese papers must use document classes and xelatex or lualatex engines that support Chinese, otherwise the table of contents titles and entries are prone to errors.

When writing a paper, the table of contents is usually the last part that gets noticed. Many people use LaTeX for the first time. After writing the text according to the template, the table of contents page is empty, or the page numbers do not match. The LaTeX paper table of contents generation instruction itself is not complicated, but it depends on the title command, compilation times, and introduction area settings. If any link goes wrong, the table of contents will be abnormal.

This article only talks about the function of the directory: what instructions to use to generate it, how many times it needs to be compiled, and what to check when a problem occurs. After reading, you should be able to add a table of contents to your document and determine whether the exception is caused by the number of compilations, the way the title is written, or settings. Template selection and the overall writing process are not expanded upon here.

Which command is used to generate a table of contents for a LaTeX paper? One sentence conclusion

Write \tableofcontents at the beginning of the text and before the title command, and then compile it at least twice. The table of contents will be automatically generated based on the existing chapter titles.

Your situationRecommended practicesReasons
Ordinary articles, only use sections and subsectionsUse the article class, write \tableofcontents before the text, the level is determined by section and subsectionThe table of contents only collects entries written by the title command, no manual entry is required
Books or dissertations need to be divided into chaptersUse the book or report class, use chapter to divide into chapters, the table of contents will display chapters and sections at the same timeThese two types of document classes use chapter as a high-level title
Chinese paperUse Chinese document classes such as ctexart and compile with xelatex or lualatexChinese fonts and line breaks depend on the compilation engine that supports Unicode
There are appendices and chart listsAppendices use the appendix command, and chart lists use listoffigures and listoftablesThese are independent lists, each collecting the corresponding environment
The directory page number or entry is always wrongContinuous compilation until the output result no longer changesThe page number must be written to the auxiliary file after one compilation is completed, and it can be read back in the next compilation

Before you start: Confirm these points first

  • Whether the document class supports chapter division. The article class does not have a chapter command, and an error will be reported if you write it; the school template usually has a document class specified, so follow the template first.
  • Whether the title is written using standard commands. The directory only recognizes commands such as section and subsection. Ordinary paragraphs in bold or enlarged font size will not be included in the table of contents. This is a common reason for missing items.
  • Whether the compilation engine matches. When there is Chinese in the text, pdflatex is prone to errors or garbled characters, so xelatex or lualatex should be used instead.
  • Whether there is a directory setting for the template. Many templates have already defined directory formats in the preamble area. Duplicate definitions may cause conflicts. Read the template description before making any changes.
  • Whether auxiliary files remain. Old .toc files will cause the table of contents to display outdated content. Cleaning and recompiling can eliminate many seemingly strange problems.

Steps to generate a table of contents in LaTeX

  1. Select the document class in the introductory area, such as article, or the Chinese class provided by the school, and load the required Chinese support package.
  2. Confirm the directory title and level settings in the introductory area. If the template has been defined, do not set it again.
  3. After \begin{document}, after the title page and before the first chapter title, write \tableofcontents.
  4. Use commands such as section and subsection to number the headings at each level, and make sure that the heading text is written within the curly braces of the command.
  5. Complete the first compilation using xelatex or the engine specified by the template. At this time, the directory may be empty or only have some entries.
  6. Compile once or twice more to allow the entries and page numbers in the auxiliary files to be read into the table of contents.
  7. If you need to limit the collection level, use \setcounter{tocdepth}{2} in the introduction area. The number 2 means it is included in the section.
  8. Open the PDF and check the contents page. If there are still problems, troubleshoot them one by one in the table in the next section.

Check each item after completion

Check itemsHow to seeWhat to do if there is a problem
Whether there are entries in the catalogThe catalog page lists titles at all levelsIf it is empty, compile again; if it is still empty, confirm that the title uses standard commands
Title textVerbatically consistent with the text titleIf inconsistent, check whether it has been modified and not recompiled
Page numberCorresponds to the page number in the footer of the textIf it does not match, compile a few more times, clean up the auxiliary files and then recompile
Levels and indentationChapters, sections, and subsections are clearly hierarchicalAdjust tocdepth, or check whether lower-level commands are misused
Question markThere is no ?? in the directoryThe presence of a question mark indicates that the reference has not been resolved, continue compiling until it disappears
Chinese displayNo garbled characters and no boxesConfirm to use xelatex or lualatex and check whether the Chinese class is loaded

If you have the UniDoc web editor (app.unidoc.top) at hand, it supports conversion to and from LaTeX. You can put the content of the source file into the visual interface and check whether the title level is consistent with your expectations. This is only an auxiliary check, and the local compilation result will ultimately prevail.

📊 Core comparison: How to deal with titles that are not included in the table of contents

Papers often have titles such as abstracts, acknowledgments, and statements that do not require numbering. Whether they enter the directory depends on how the title command is written.

Writing methodWhether to numberWhether to enter the directoryApplicable scenarios
Standard commands such as sectionisisa regular section of the text
Commands with an asterisk, such as section*NoNoPages such as acknowledgments and statements that do not need to appear in the table of contents
Add addcontentsline to the command with an asteriskNoYesTitles such as abstracts and references that are not numbered but need to appear in the table of contents

The third way of writing is to write addcontentsline after the asterisked title and specify the directory level and title text. This maintains the layout and allows the items to appear in the table of contents.

❓ Frequently Asked Questions (FAQ)

1. The directory is always empty, why?

Usually it is compiled only once, or the standard header commands are not used in the text. Compile again once or twice. When it is still empty, check whether the chapter title is actually written as a command such as section.

2. Why do two question marks appear in the directory?

Two question marks indicate that the page number of the entry has not been written to the auxiliary file. In most cases, the number of compilations is not enough. Continuously compile until it disappears; if it still appears after deleting the content, clean the auxiliary files and then recompile.

3. Why does the directory title show Contents?

When using classes such as English article, the default title is Contents. Chinese papers can use the Chinese document class instead, or use \renewcommand in the introduction area to change the contentsname to "directory". The specific writing method is subject to the template requirements.

4. What should I do if a certain chapter does not appear in the table of contents?

First check to see if it uses the asterisked title command, and then check to see if the tocdepth value is lower than that level. Remove the asterisk or increase the tocdepth and compile again.

📝 Summary

The core of the LaTeX paper table of contents generation instructions is: write \tableofcontents at the beginning of the text, use standard commands for the title, and compile two or three times. When you encounter a problem, first look at the number of compilations, then look at the title writing and introductory area settings. Most exceptions can be located.

Open OmniDoc to edit, convert or translate your LaTeX document

Updated 2026-11-11