Template:TOCfloat: Difference between revisions

From OniGalore
Jump to navigation Jump to search
(based on Wikipedia's "TOC left" template)
 
(forgot to update end of doc)
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly><div style="clear:left; margin-bottom:0.5em; float:left; padding:0.5em 1.4em 0.8em 0; background:none; width:{{{width|{{{1|auto}}}}}};" {{#if:{{{limit|}}}|class="toclimit-{{{limit}}}"}}>__TOC__</div></includeonly><noinclude>Especially for articles which do not have a lede, a long Table Of Contents (TOC) can be visually unsettling -- "Hey, where's the article? There's just this long box!" Use this template where it seems appropriate to make the TOC a floating table, so the article starts next to it, not below it. Pass it a "width" parameter to specify width. You can also pass in a "limit" parameter to limit the TOC to a certain level of hierarchy; for instance, <nowiki>{{TOCfloat|limit=2}}</nowiki> would only show level 2 headers (==), keeping the table short.
<includeonly><div style="clear:left; margin-bottom:0.5em; float:{{{side|left}}}; padding:0.5em 1.4em 0.8em 0; background:none; width:{{{width|auto}}};" class="{{#ifeq:{{{numbers}}}|no|nonumtoc}} {{#if:{{{limit|}}}|toclimit-{{{limit}}}}}">__TOC__</div></includeonly><noinclude>Especially for articles which do not need a [[wp:WP:LEDE|lede]], a long table of contents (TOC) can be visually unsettling "Hey, where's the article? There's just this long box!" Use this template to make the TOC a floating table, so that the article text wraps around it. Now, sometimes a long TOC is the best approach, as in [[Quotes/Speech]] where we want the reader to be able to choose from the full directory of conversations in the game without any distracting text to the right. But for a more normal article like [[Daodan DLL]] it would look bad if the article didn't start until after the lengthy TOC.
 
See the [[Template:TOClimit|TOClimit]] template if you just want to omit lower-level section headers from the TOC, but note that this TOCfloat template does perform the same function if you use the "limit" parameter. See the [[Template:TOCnonum|TOCnonum]] template if you just want to omit automatic numbering from the TOC, but note that TOCfloat also offers the parameter "numbers=no" for this purpose.
 
Note: It's important to have a grasp of proper wiki article layout, because this template includes the magic word <nowiki>__TOC__</nowiki> which determines the TOC's position within the article. This mean that, in order to preserve a standard article layout, <u>you have to place the template markup between the lede text (if there is any) and the first subheader</u> in the article. You are also expected to avoid the use of level 1 headers (=) when writing articles. The Daodan article linked above demonstrates proper layout with (1) a lede that describes the DLL briefly without the use of a section header, followed by (2) the TOCfloat template, followed by (3) the article's body with subheaders. The fact that the body is now wrapping around the TOC does not change the order of layout elements; it merely improves its appearance.
 
Optional parameters:
*"side" — this is passed to the float property, so your only meaningful choices are "left" or "right" (default is "left")
*"width" — e.g., "300px" or "30%"; this works in unusual ways: you can make the TOC more narrow than it would be normally (forcing line wrap on header names that exceed that width), but if you supply a width that is greater than the "auto" width (determined by the length of the longest header name), then the TOC stays at the "auto" width, but with a whitespace margin added to the right. When you use the template's default float:left style, this margin appears between the left-aligned TOC and the article text that wraps around it, which one could use to insert a small bit of extra space for aesthetic purposes. When you supply "side=right", however, excess width is still placed to the right of the TOC, making an undesirable white area as a sort of third column after the wrapped article text and the TOC.
*"limit" — limits the TOC to a certain level of hierarchy; for instance, <tt><nowiki>{{TOCfloat|limit=2}}</nowiki></tt> would only show level 2 headers (==), keeping the table short.
*"numbers=no" — removes automatic numbering from the TOC; this is preferable visually when the article section names themselves already start with numbers.
 
[[Category:Basic formatting templates]]
[[Category:Basic formatting templates]]
</noinclude>
</noinclude>

Latest revision as of 14:53, 14 December 2021

Especially for articles which do not need a lede, a long table of contents (TOC) can be visually unsettling – "Hey, where's the article? There's just this long box!" Use this template to make the TOC a floating table, so that the article text wraps around it. Now, sometimes a long TOC is the best approach, as in Quotes/Speech where we want the reader to be able to choose from the full directory of conversations in the game without any distracting text to the right. But for a more normal article like Daodan DLL it would look bad if the article didn't start until after the lengthy TOC.

See the TOClimit template if you just want to omit lower-level section headers from the TOC, but note that this TOCfloat template does perform the same function if you use the "limit" parameter. See the TOCnonum template if you just want to omit automatic numbering from the TOC, but note that TOCfloat also offers the parameter "numbers=no" for this purpose.

Note: It's important to have a grasp of proper wiki article layout, because this template includes the magic word __TOC__ which determines the TOC's position within the article. This mean that, in order to preserve a standard article layout, you have to place the template markup between the lede text (if there is any) and the first subheader in the article. You are also expected to avoid the use of level 1 headers (=) when writing articles. The Daodan article linked above demonstrates proper layout with (1) a lede that describes the DLL briefly without the use of a section header, followed by (2) the TOCfloat template, followed by (3) the article's body with subheaders. The fact that the body is now wrapping around the TOC does not change the order of layout elements; it merely improves its appearance.

Optional parameters:

  • "side" — this is passed to the float property, so your only meaningful choices are "left" or "right" (default is "left")
  • "width" — e.g., "300px" or "30%"; this works in unusual ways: you can make the TOC more narrow than it would be normally (forcing line wrap on header names that exceed that width), but if you supply a width that is greater than the "auto" width (determined by the length of the longest header name), then the TOC stays at the "auto" width, but with a whitespace margin added to the right. When you use the template's default float:left style, this margin appears between the left-aligned TOC and the article text that wraps around it, which one could use to insert a small bit of extra space for aesthetic purposes. When you supply "side=right", however, excess width is still placed to the right of the TOC, making an undesirable white area as a sort of third column after the wrapped article text and the TOC.
  • "limit" — limits the TOC to a certain level of hierarchy; for instance, {{TOCfloat|limit=2}} would only show level 2 headers (==), keeping the table short.
  • "numbers=no" — removes automatic numbering from the TOC; this is preferable visually when the article section names themselves already start with numbers.