LaTeX: Table of contents
This page was translated from German with AI. It has not been checked by a native speaker. Original page in German
\tableofcontents, creates the whole table with numbers and page numbers. The only important thing: after changes, compile twice.
The video
In the video you see TeXstudio under Linux. The orange frame always shows the spot in question. Under Windows and macOS TeXstudio looks exactly the same. The practice file above is the state at the start of the video – so you can follow along with each part separately.
Contents of the video
- 0:00 What it is about
- 0:19 Inserting the table
- 0:55 The table
- 1:09 A page of its own
- 1:26 Compiling twice
- 1:57 How deep?
- 2:08 Summary
The most important points
Compiling twice
On the first run LaTeX collects the headings and their pages in an auxiliary file, on the second it sets the table from it. If only page numbers shift, LaTeX does not report it, and TeXstudio does not recompile by itself. So before handing in, always compile twice.
With \clearpage after the table the introduction starts on a new page. \setcounter{tocdepth}{2} in the preamble shows only chapters and subchapters.
The worksheet
Here you can see the worksheet for the video (in German). You download the practice files above and work in your own editor. The hints are printed upside down – turn the sheet only when you cannot get on by yourself. You can also open it as a PDF.
📄 Open worksheet (PDF, German)
Show the worksheet solutions
Try it yourself
Task
You inserted a chapter and compiled once. In the table the conclusion still says page 6, but it starts on page 7. What do you do?
Show solution
Compile once more. On the first run LaTeX wrote the new page into the auxiliary file, on the second it takes it into the table. You never change anything there by hand.
Keep learning with a language model
Explain to me why LaTeX needs two runs for the table of contents and references. Use an everyday example for it and then check with a question whether I have understood it.
How this was made: The idea and the choice of topics are mine. A language model (LLM) drafted the script, the sample paper, the tasks and this page following my instructions. The screen recordings were made automatically by a script in TeXstudio under Linux, which checked the finished PDF after every step: are margins, font, numbers and references right, are there warnings? The voice was generated with Qwen3-TTS, modelled on my own voice.
The sample paper about the thread pendulum is invented, and so are the person “Alex Beispiel” and the two sources in the bibliography.
The videos, worksheets, practice files, texts and prompts in this series are licensed under CC BY 4.0: you may use, change and share them if you name the source.