Automatic Table of Contents

A table of contents (TOC) is an index of section titles that is automatically generated from the document’s structure.

Activate the TOC

To enable the autogenerated TOC, set the toc document attribute. The toc attribute is activated with an attribute entry in the document header.

Example 1. Enable TOC with the toc attribute
= The Intrepid Chronicles
Kismet Lee; B. Steppenwolf; Pax Draeke
:toc: (1)

== Certain Peril

Daylight trickles across the cobblestones...

=== A Recipe for Potion

We have to harvest the leaves by the light of the teal moons...

==== Searching for Ginseng

Crawling through the twisted understory...

== Dawn on the Plateau

Hanging from...
1 Set the toc attribute in the header using an attribute entry. When the value of toc is left blank, the processor will use the attribute’s default value.

By default, the TOC is rendered directly below the document header, is titled Table of Contents, and contains section 1 and section 2 level titles only. The result of Example 1 is displayed below.

Default table of contents

You can customize the title of the TOC, the depth of the section levels, and the position of the TOC in the document. However, not all of the attributes are supported by all converters. See TOC Attributes Reference for which attributes are available to each converter.

Activate the TOC from the CLI

The toc attribute can also be specified via the command line (-a toc).

TOC enabled via the CLI
$ asciidoctor -a toc my-document.adoc