Help:Table of contents: Difference between revisions
m (Text replacement - "Category:Help" to "Category:HelpCategory:Help under review") Tag: Reverted |
m (Text replacement - "Category:HelpCategory:Help under review" to "Category:Help") Tag: Manual revert |
||
Line 60: | Line 60: | ||
Please see [[Template:TOC scroll]]. This is especially useful for a long article's table of contents. | Please see [[Template:TOC scroll]]. This is especially useful for a long article's table of contents. | ||
[[Category:Help | [[Category:Help]] |
Latest revision as of 23:10, 7 October 2024
A table of contents (TOC), usually headed simply Contents, is a linked list of section headings on a page before the main contents of a page. For each page with four or more section headings, a table of contents is automatically generated and updated after each change to the headings.
By default
- it appears below the lead section, however it can be manually positioned at another location on the page
- it includes all section heading levels, however this can be changed as well by limiting the depth of the table of contents
The creation of a table of contents is prevented if:
- (for a user) preferences are set to turn it off
- it is turned off in VisualEditor's Page Setting's Table of contents
- (for an article) the magic word
__NOTOC__
(with two underscores on either side of the word) is added to the article
Determining which editor to use
- When using magic words, you must add them using enhanced editor for the text will just appear on the page.
- Templates can be added with either editor
- Adding a template with VisualEditor is the recommended path
- Help:Templates#Enhanced editor
Positioning the TOC
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. 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.
Floating the TOC
The TOC can, in some instances, be floated/aligned either right or left using {{TOC right}}
or {{TOC left}}
templates when it is beneficial to the layout of the article, or when the default TOC gets in the way of other elements.
Before changing the default TOC to a floated TOC, consider the following guidelines:
- If an article will be adversely affected by the change, don't float the TOC.
- If floating the TOC, it should be placed after the lead section of the wiki markup for consistency. Users of screen readers do not expect any text between the TOC and the first heading, and having no text above the TOC is confusing. See the last line in the information about elements of the lead section.
- When floating a TOC, check whether the page layout will be harmed if the TOC is hidden by the user.
- Long lists may create very long TOCs. The TOC should not be longer than necessary, whether it is floated or not.
{{TOC limit}}
can be used to reduce the length of the TOC by hiding nested subsections, rather than a floating TOC. - The default TOC is placed before the first headline, but after any introductory text (unless changed by the page's editors). If the introductory summary is long enough that a typical user has to scroll down to see the top of the TOC, you may float the TOC so it appears closer to the top of the article. However, the floating TOC should in most cases follow at least the first paragraph of article text.
- Floating a wide TOC will produce a narrow column of readable text for users with low resolutions. If the TOC's width exceeds 30% of the user's visible screen (about twice the size of the Wikipedia navigation bar to the left), then it is not suitable for floating. (Percentages assume a typical user setup.) If text is trapped between a floating TOC and an image, floating can be cancelled at a certain text point, see Forcing a break.
- If the TOC is placed in the general vicinity of other floated images or boxes, it can be floated as long as the flowing text column does not become narrower than 30% of the average user's visible screen width.
- A left-floated TOC may affect bulleted or numbered lists.
Limiting the depth of the TOC
When an article or project page has a very large number of subsections, it may be appropriate to hide lower-level subsections from the TOC. You can specify a limit for the lowest-level section that should be displayed using {{TOC limit|limit=n}}
, where n is the number of lowest-level section header that should be displayed.
It can also be limited with {{TOC right}}
- {{TOC right|limit=2}}.
Linking to the TOC
The TOC is automatically generated with HTML id="toc"
. You can make a link to it with [[#toc]]
:
- Same page:
- wikicode:
[[#toc|Contents]]
- link: Contents
- wikicode:
- Different page:
- wikicode:
[[Help:Wiki markup#toc|Contents]]
- link: Contents
- wikicode:
Replacing the default TOC
The auto-generated TOC is not maximally appropriate or useful in all article types, such as long list articles and glossaries, so there are numerous replacement templates. To use one, place the alternative TOC template, such as {{CompactTOC8}}
(which can be customized for many list styles) or
{{TOC scroll}}
, where needed.
Scrolling table of contents
Please see Template:TOC scroll. This is especially useful for a long article's table of contents.