Jump to content


From mediawiki.org
This page is a translated version of the page Manual:Table of contents and the translation is 51% complete.
Outdated translations are marked like this.




  • ‎<sup>, ‎<sub>[1]
  • ‎<i>[2]
  • ‎<b>[3]
  • ‎<bdi>[4]
  • <span dir="rtl">, <span dir="ltr">[5]
  • ‎<s>, ‎<strike>[6]
  • ‎<q>[7]

不会为html标记(手册:$wgRawHtml )中的章节标题生成目录。



使用某些模板,例如Template:Compact ToC(可在英文Wikipedia上找到),将替换通常的目录功能。


TOC的默认位置位于第一节标题的正上方。 任何先前的文本都会在TOC之前。 要将其放置在其他位置,请在页面上的目标位置使用魔术字__TOC__

皮肤可以使用Extension:DeToc 移除目录或将目录移动到页面的其他部分。





一个合理的方式是将TOC的宽度调整为页面宽度的百分比。 例如: {{TOC left|width=30%}}


TOC显示的最深标题级别由$wgMaxTocLevel 定义。 要为单个页面自定义此规则,如果在页面CSS中定义了合适的CSS规则,则可以将TOC包含在具有类toclimit-<limit>的元素中。

有关示例实现,请参阅Template:TOC Template:TOC/limit-styles.css中的相关规则。


默认情况下,目录会自动为这部分编号。 本节标题未进行编号。 目录的此行为可以通过多种方式自定义:

  • 如果存在在MediaWiki:Common.css中定义为.tocnumber { display: none; }的合适的类,则可以在TOC中取消自动生成的节编号。

To do this selectively, a wrapper element can be placed around the TOC, as in <div class="noautonum">__TOC__</div> on the page, and .noautonum .tocnumber { display: none; } at MediaWiki:Common.css.

It is also possible to add numbering to headings themselves using JavaScript, as explained at Snippets/Auto-number headings .


Different languages have different ways of expressing TOCs and how its (sub)section numbering is done. Also, the different style guides of many languages differ in what style of TOC and TOC (sub)section numbering scheme they recommend for writers to use.

The different w:style guides of each language sometimes recommend different typographic conventions to follow.

It's important to note that most languages don't even have any style guide for writing in that language (and many languages don't have a written form entirely), so people usually use the most common style based on existing written convention (not prescribed, but simply 'standard' due to popular usage), which makes the written use of many languages have a sort of 'fluid' punctuation, spelling/orthography and even [personal changes of the very] grammar [of that particular language]. w:Westernization has influenced alphabet and non-alphabet writing systems, with many languages simply copying or being artificially converted to European-style typographic and w:punctuational conventions.

An example on how to change the style of a TOC to a localized one is given below:

Some languages put a dot after a (sub)section ordinal number, e.g. they do not use the following TOC style:

1 Section [1]
1.1 Subsection [1.1]
2 Section [2]
2.1 Subsection [2.1]
3 Section [3]
3.1 Subsection [3.1]
3.1.1 Subsubsection [3.1.1]
3.1.2 Subsubsection [3.1.2]

But use one like so:

1. Section [1.]
1.1. Subsection [1.1.]
2. Section [2.]
2.1. Subsection [2.1.]
3. Section [3.]
3.1. Subsection [3.1.]
3.1.1. Subsubsection [3.1.1.]
3.1.2. Subsubsection [3.1.2.]

(Notice the addition of dots after ordinal numerals before the section names!)

It's possible to produce that effect using w:CSS. Put the following CSS code in a shared CSS file of your MediaWiki installation and it should work:

.tocnumber:after { content: '.' }

where the symbol between the single quotation marks is the sign after a (sub)section number.

Also, see bugzilla:43494 and bugzilla:33450 for details on related i18n problems of TOCs.


The TOC can be made to display as a floating element on the page, with text flowing around it.

For this, enclose the TOC in an element with the CSS style float:left; or float:right;.

See Template:TOC for an example implementation.




See also

  1. From MediaWiki 1.11 (2007年9月). See phab:T10393.
  2. From MediaWiki 1.19 (2011年11月). See phab:T28375.
  3. From MediaWiki 1.19 (2011年12月). See phab:T28375.
  4. From MediaWiki 1.25/wmf14 (). See phab:T74884.
  5. From MediaWiki 1.21/wmf1 (). See phab:T37167.
  6. From MediaWiki 1.28/wmf.21 (). See phab:T35715.
  7. From MediaWiki 1.39.0-wmf.6 (). See phab:T251672.