# Set Pandoc's table of contents depth for a readable export

Canonical: https://githtml.com/guides/pandoc-table-of-contents-depth
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

Enable Pandoc's table of contents only after the source headings form a useful outline, then choose a depth that exposes major reader tasks without listing every minor note. Verify the generated links in the final HTML. A table of contents reflects document structure; it cannot repair vague headings or an article whose sections are organized around the wrong questions.

## Read the outline without the body

Extract or inspect the headings and ask whether they describe a sensible route through the document. Repeated labels such as Details or More information provide little value in a contents list. Rename them around the actual subject before generating navigation. Decide which sections readers need to jump to and which are small supporting subsections. A short memo may not need a contents list at all. For a longer reference, a shallow list can be more useful than a complete inventory of every heading. Keep this decision tied to the document's reading task rather than a default applied to every export.

## Choose the depth with a representative document

The sample requests a contents list limited to two heading levels. Confirm how the installed version and template present it, especially if the source uses unusual heading levels or includes several chapter files. Add a few representative deeper subsections to the fixture so you can see what is intentionally omitted. Do not confuse contents depth with heading renumbering or automatic section numbering; those are separate presentation choices. If the output needs a different title for the contents block, use the documented template or metadata mechanism and check the result. Avoid hand-editing generated links that will be replaced on the next conversion.

````sh
pandoc handbook.md --standalone --toc --toc-depth=2 \
  --metadata title="Sample handbook" \
  --output=handbook.html
````

## Test navigation after every structural edit

Follow each generated contents link in the HTML and confirm that it reaches the intended section. Pay particular attention to repeated headings and headings containing punctuation. Check whether the contents list itself overwhelms the opening on a narrow screen; reducing depth can improve the first reading experience without removing information from the document. When combining source files, inspect whether the resulting hierarchy still makes sense as one document. Preserve the source outline and export flags together so future builds remain predictable. A portable HTML reader can display the resulting document, but the authoring tool remains responsible for generating and validating the navigation.

1. Review the heading-only outline and replace vague labels before enabling the contents list.
2. Select the shallowest depth that still exposes meaningful reader tasks.
3. Follow generated links in the final output rather than guessing their fragments.
4. Recheck the opening layout and hierarchy after adding chapters or moving sections.

## Sources and further reading

- [Pandoc User's Guide](https://pandoc.org/MANUAL.html)

## Related guides

- [Prepare Sphinx autodoc without importing production side effects](https://githtml.com/guides/sphinx-autodoc-import-side-effects)
- [Run Sphinx doctests without mistaking them for a full test suite](https://githtml.com/guides/sphinx-doctest-examples-local-check)
- [Diagnose missing Sphinx intersphinx references](https://githtml.com/guides/sphinx-intersphinx-missing-reference)
- [Add MyST Markdown to Sphinx without assuming plain Markdown behavior](https://githtml.com/guides/sphinx-myst-markdown-authoring-boundary)

Editorial approach: https://githtml.com/guides/about
