Help:Lists

From IoTWiki
Revision as of 13:45, 1 November 2017 by Kaganer (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

<languages/> Template:TNT

<translate> This page deals with creating lists in Mediawiki.

List basics

<tvar|mw>Template:Ll</> offers three types of lists: ordered lists, unordered lists, and definition lists. In the following sections, ordered lists are used for examples. Unordered lists would give corresponding results. </translate>

<translate> Wikitext</translate> <translate> Rendering</translate>
<translate>
<!--T:6-->
* Lists are easy to do:
** start every line
* with a star
** more stars mean
*** deeper levels</translate>
<translate>
  • Lists are easy to do:
    • start every line
  • with a star
    • more stars mean
      • deeper levels</translate>
<translate>
<!--T:8-->
* A newline
* in a list  
marks the end of the list. 
Of course
* you can
* start again.</translate>
<translate>
  • A newline
  • in a list

marks the end of the list. Of course

  • you can
  • start again.</translate>
<translate>
<!--T:10-->
# Numbered lists are good
## very organized
## easy to follow</translate>
<translate>
  1. Numbered lists are good
    1. very organized
    2. easy to follow</translate>
<translate>
<!--T:12-->
* You can also
** break lines
** like this</translate>
<translate>
  • You can also
    • break lines
    • like this</translate>
<translate>
<!--T:14-->
; Definition lists
; item : definition
; semicolon plus term
: colon plus definition</translate>
<translate>
Definition lists
item 
definition
semicolon plus term
colon plus definition</translate>
<translate>
<!--T:16-->
; Mixed definition lists
; item 1 : definition
:; sub-item 1 plus term
:: two colons plus definition
:; sub-item 2 : colon plus definition
; item 2 
: back to the main list</translate>
<translate>
Mixed definition lists
item 1 
definition
sub-item 1 plus term
two colons plus definition
sub-item 2 
colon plus definition
item 2
back to the main list</translate>
<translate>
<!--T:18-->
* Or create mixed lists
*# and nest them
*#* like this
*#*; definitions
*#*: work:
*#*; apple
*#*; banana
*#*: fruits</translate>
<translate>
  • Or create mixed lists
    1. and nest them
      • like this
        definitions
        work:
        apple
        banana
        fruits</translate>
Template:-

<translate>

Paragraphs in lists

For simplicity, list items in wiki markup cannot be longer than a paragraph. A following blank line will end the list and reset the counter on ordered lists. Separating unordered list items usually has no noticeable effects.

Paragraphs can be forced in lists by using HTML tags. Two line break symbols, <tvar|brtags><br /><br /></>, will create the desired effect. So will enclosing all but the first paragraph with <tvar|ptag><p>...</p></>.

For a list with items of more than one paragraph long, adding a blank line between items may be necessary to avoid confusion.

Continuing a list item after a sub-item

In HTML, a list item may contain several sublists, not necessarily adjacent; thus there may be parts of the list item not only before the first sublist, but also between sublists, and after the last one; however, in wiki-syntax, sublists follow the same rules as sections of a page: the only possible part of the list item not in sublists is before the first sublist.

In the case of an unnumbered first-level list in wikitext code this limitation can be overcome by splitting the list into multiple lists; indented text between the partial lists may visually serve as part of a list item after a sublist; however, this may give, depending on CSS, a blank line before and after each list, in which case, for uniformity, every first-level list item could be made a separate list.

Numbered lists illustrate that what should look like one list may, for the software, consist of multiple lists; unnumbered lists give a corresponding result, except that the problem of restarting with 1 is not applicable. </translate>

<ol>
  <li><translate><!--T:28--> list item</translate> A1
    <ol>
      <li><translate><!--T:29--> list item</translate> B1</li>
      <li><translate><!--T:30--> list item</translate> B2</li>
    </ol><translate><!--T:31--> continuing list item</translate> A1
  </li>
  <li><translate><!--T:32--> list item</translate> A2</li>
</ol>
  1. <translate> list item</translate> A1
    1. <translate> list item</translate> B1
    2. <translate> list item</translate> B2
    <translate> continuing list item</translate> A1
  2. <translate> list item</translate> A2
vs.
<translate>
<!--T:38-->
#list item A1
##list item B1
##list item B2
#:continuing list item A1
#list item A2</translate>
<translate>
  1. list item A1
    1. list item B1
    2. list item B2
    continuing list item A1
  2. list item A2</translate>

<translate> One level deeper, with a sublist item continuing after a sub-sublist, one gets even more blank lines; however, the continuation of the first-level list is not affected: </translate>

<translate>
<!--T:41-->
#list item A1
##list item B1
###list item C1
##:continuing list item B1
##list item B2
#list item A2
</translate>

<translate> gives

  1. list item A1
    1. list item B1
      1. list item C1
      continuing list item B1
    2. list item B2
  2. list item A2</translate>

<translate> See also <tvar|1>Template:Tim</>.

Changing the list type

The list type (which type of marker appears before the list item) can be changed in CSS by setting the <tvar|list-style-type>list-style-type</> property: </translate>

<translate> Wikitext</translate> <translate> Rendering</translate>
<ol style="list-style-type:lower-roman">
  <li><translate><!--T:48--> About the author</translate></li>
  <li><translate><!--T:49--> Foreword to the first edition</translate></li>
  <li><translate><!--T:50--> Foreword to the second edition</translate></li>
</ol>
  1. <translate> About the author</translate>
  2. <translate> Foreword to the first edition</translate>
  3. <translate> Foreword to the second edition</translate>
<ol style="list-style-type:lower-alpha">
  <li><translate><!--T:54--> About the author</translate></li>
  <li><translate><!--T:55--> Foreword to the first edition</translate></li>
  <li><translate><!--T:56--> Foreword to the second edition</translate></li>
</ol>
  1. <translate> About the author</translate>
  2. <translate> Foreword to the first edition</translate>
  3. <translate> Foreword to the second edition</translate>

<translate>

Extra indentation of lists

In a numbered list in a large font, some browsers do not show more than two digits, unless extra indentation is applied (if there are multiple columns: for each column). This can be done with CSS:</translate>

ol { margin-left: 2cm}

<translate> or alternatively, like below. </translate>

<translate> Wikitext</translate> <translate> Rendering</translate> <translate> Comments</translate>
:#abc
:#def
:#ghi
 
  1. abc
  2. def
  3. ghi
link1>http://www.w3.org/TR/html4/struct/lists.html#edef-DL</> definition list] without definition terms, and with the items as definition descriptions, hence indented. However, if the colons are in front of the codes "*" or "#" of an unordered or ordered list, the list is treated as one definition description, so the whole list is indented.</translate>
<ul>
  <ol>
    <li>abc</li>
    <li>def</li>
    <li>ghi</li>
  </ol>
</ul>
    1. abc
    2. def
    3. ghi
margin-left>style="margin-left: 2em"</>, causing indentation of the contents. This is the most versatile method, as it allows starting with a number other than 1, see below.</translate>
<ul>
#abc
#def
#ghi
</ul>
    1. abc
    2. def
    3. ghi
<translate> Like above, with the content of the "unordered list without any list items", which itself is an ordered list, expressed with # codes. The HTML produced, and hence the rendering, is the same. This is the recommended method when starting the list at 1.</translate>

<translate> To demonstrate that all three methods show all digits of 3-digit numbers, see [[<tvar|metalink1>m:Help:List demo</>|List demo]].

Specifying a starting value

Specifying a starting value is possible with HTML syntax. (W3C has deprecated the <tvar|start>start</> and <tvar|value>value</> attributes as used below in HTML 4.01 and XHTML 1.0. But as of 2007, no popular web browsers implement CSS counters, which were to replace these attributes. Wikimedia projects use XHTML Transitional, which contains the deprecated attributes.) </translate>

<ol start="9">
<li><translate><!--T:72--> Amsterdam</translate></li>
<li><translate><!--T:73--> Rotterdam</translate></li>
<li><translate><!--T:74--> The Hague</translate></li>
</ol>
  1. <translate> Amsterdam</translate>
  2. <translate> Rotterdam</translate>
  3. <translate> The Hague</translate>

<translate> Or:</translate>

<ol>
<li value="9"><translate><!--T:79--> Amsterdam</translate></li>
<li value="8"><translate><!--T:80--> Rotterdam</translate></li>
<li value="7"><translate><!--T:81--> The Hague</translate></li>
</ol>
  1. <translate> Amsterdam</translate>
  2. <translate> Rotterdam</translate>
  3. <translate> The Hague</translate>

<translate>

Comparison with a table

Apart from providing automatic numbering, the numbered list also aligns the contents of the items, comparable with using table syntax: </translate>

{|
|-
| align=right |  9.|| <translate><!--T:87--> Amsterdam</translate>
|-
| align=right | 10.|| <translate><!--T:88--> Rotterdam</translate>
|-
| align=right | 11.|| <translate><!--T:89--> The Hague</translate>
|}

gives

9. <translate> Amsterdam</translate>
10. <translate> Rotterdam</translate>
11. <translate> The Hague</translate>

<translate> This non-automatic numbering has the advantage that if a text refers to the numbers, insertion or deletion of an item does not disturb the correspondence.

Multi-column lists

See also <tvar|coltemplates>Template:Col-begin, Template:Col-break, Template:Col-end</>.

Multi-column bulleted list

</translate>

<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
<translate>
<!--T:97-->
* apple
* carpet
* geography
* mountain
* nowhere
* postage
* ragged
* toast
</translate>
</div>

<translate> gives:</translate>

<translate>

  • apple
  • carpet
  • geography
  • mountain
  • nowhere
  • postage
  • ragged
  • toast

</translate>

<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
<translate>
<!--T:100-->
* apple
* carpet
* geography
* mountain
* nowhere
* postage
* ragged
* toast
</translate>
</div>

<translate> gives:</translate>

<translate>

  • apple
  • carpet
  • geography
  • mountain
  • nowhere
  • postage
  • ragged
  • toast

</translate>

<translate>

Multi-column numbered list

</translate>

<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
<translate>
<!--T:104-->
#apple
#carpet
#geography
#mountain
#nowhere
#postage
#ragged
#toast
</translate>
</div>

<translate> gives:</translate>

<translate>

  1. apple
  2. carpet
  3. geography
  4. mountain
  5. nowhere
  6. postage
  7. ragged
  8. toast

</translate>

<translate> Below a starting value is specified, with HTML-syntax (for the first column either wiki-syntax or HTML-syntax can be used).

In combination with the extra indentation explained in the previous section: </translate>

{| valign="top"
|-
|<ul><ol start="125"><li>a<li>bb<li>ccc</ol></ul>
|<ul><ol start="128"><li>ddd<li>ee<li>f</ol></ul>
|}

<translate> gives</translate>

    1. a
    2. bb
    3. ccc
    1. ddd
    2. ee
    3. f

<translate> Using <tvar|templatelink1>Template:Tim</> the computation of the starting values can be automated, and only the first starting value and the number of items in each column except the last has to be specified. Adding an item to, or removing an item from a column requires adjusting only one number, the number of items in that column, instead of changing the starting numbers for all subsequent columns. </translate>

{{Multi-column numbered list|125|a<li>bb<li>ccc|3|<li>ddd<li>ee<li>f}}

<translate> gives:</translate>

Template:Multi-column numbered list

{{Multi-column numbered list|lst=lower-alpha|125|a<li>bb<li>ccc|3|<li>ddd<li>ee|2|<li>f}}

<translate> gives:</translate>

Template:Multi-column numbered list

{{Multi-column numbered list|lst=lower-roman|125|a<li>bb<li>ccc|3|<li>ddd<li>ee|2|<li>f}}

<translate> gives:</translate>

Template:Multi-column numbered list

{{Multi-column numbered list|lst=disc||a<li>bb<li>ccc||<li>ddd<li>ee||<li>f}}

<translate> gives:</translate>

Template:Multi-column numbered list

<translate>

Streamlined style or horizontal style

It is also possible to present short lists using very basic formatting, such as: </translate>

<translate><!--T:117--> ''Title of list:'' example 1, example 2, example 3</translate>

<translate> Title of list: example 1, example 2, example 3</translate>

<translate> This style requires less space on the page, and is preferred if there are only a few entries in the list, it can be read easily, and a direct edit point is not required. The list items should start with a lowercase letter unless they are proper nouns.

Tables

A one-column table is very similar to a list, but it allows sorting. If the wikitext itself is already sorted with the same sortkey, this advantage does not apply. A multiple-column table allows sorting on any column.

See also [[<tvar|wikipedialink1>:en:Wikipedia:When to use tables</>|When to use tables]].

Changing unordered lists to ordered ones

With the CSS</translate>

ul { list-style: decimal }

<translate> unordered lists are changed to ordered ones. This applies (as far as the CSS selector does not restrict this) to all ul-lists in the HTML source code:

  • those produced with *
  • those with <tvar|ul><ul></> in the wikitext
  • those produced by the system

Since each special page, like other pages, has a class based on the pagename, one can separately specify for each type whether the lists should be ordered, see [[<tvar|link1>Help:User contributions#User styles</>|User contributions]] and [[<tvar|link2>Help:What links here#User styles</>|What links here]].

However, it does not seem possible to make all page history lists ordered (unless one makes all lists ordered), because the class name is based on the page for which the history is viewed.

See also

</translate>

  • Template:Ll - <translate> creates a list with list code only at the start and end, not per item; allows easy change of list type; sorts list</translate>

[[Category:List{{#translation:}}]] [[Category:Help{{#translation:}}]]