Help:Table of contents


For each page with more than three headings, a table of contents (TOC) is automatically generated from the section headings, unless:

  • (for a user) preferences are set to turn it off
  • (for an article) the magic word __NOTOC__ (with two underscores on either side of the word) is added to the article

When either __FORCETOC__ or __TOC__ (with two underscores on either side of the word) is placed in the wikitext, a TOC is added even if the page has fewer than four headings.

With __FORCETOC__, the TOC is placed before the first section heading. With __TOC__, it is placed at the same position where this code is placed. This allows any positioning, e.g. on the right or in a table cell. In old versions of MediaWiki, it also allows multiple occurrence, e.g. in every section (However, this seems only useful if the sections are long, so that the TOCs take up only a small part of the total space.).

There may be some introductory text before the TOC, known as the "lead". Although usually a heading after the TOC is preferable, __TOC__ can be used to avoid being forced to insert a meaningless heading just to position the TOC correctly, i.e., not too low.

Using __NOTOC__ it is possible to disable the normal table of contents. Section links, as explained below, allow creating compact ToCs, e.g. alphabetical [[#A|A]] [[#B|B]] etc.

The TOC's depth can be limited by the use of Template:TOClimit. This template can reduce the number of "header levels" visible to the reader – thus avoiding the problem of an overwhelming TOC when an article has many headings and sub-headings.

This Table of contents can be forced onto a floating table on the right hand of the screen with the code below:

  {| align="right"
  | __TOC__

[edit] Globally limiting the TOC depth

It is possible to limit the depth of sub-sections to show in the TOC globally using $wgMaxTocLevel. If configuration setting $wgMaxTocLevel in LocalSettings.php is set to 3 for example, only first and second level headings show up in the TOC. Until version 1.10.0rc1, there is a bug in the parser making a limited TOC display incorrectly. A simple solution is proposed in bug report 6204.