Help:Tables

From Urban Chickens Network
(Difference between revisions)
Jump to: navigation, search
m (1 revision: help text from mediawiki.org)
 
Line 1: Line 1:
{{PD Help Page}}
+
'''Tables''' may be authored in wiki pages using either XHTML table elements directly, or using wikicode formatting to define the table. XHTML table elements and their use are well described on various web pages and will not be discussed here. The benefit of wikicode is that the table is constructed of character symbols which tend to make it easier to perceive the table structure in the article editing view compared to XHTML table elements.  
'''Tables''' may be authored in wiki pages using either XHTML table elements directly, or using wikicode formatting to define the table. XHTML table elements and their use are well described on various web pages and will not be discussed here. The benefit of wikicode is that the table is constructed of character symbols which tend to make it easier to perceive the table structure in the article editing view compared to XHTML table elements.
+
+
As a general rule, it is best to avoid using a table unless you need one. Table markup often complicates page editing.
+
  
== Wiki table markup summary ==
+
As a general rule, it is best to avoid using a table unless you need one. Table markup often complicates page editing.
{|cellpadding="5" cellspacing="0" border="1" width="60%"
+
 
|
+
== Wiki table markup summary ==
 +
 
 +
{| cellspacing="0" cellpadding="5" border="1" width="60%"
 +
|-
 +
|  
 
  <nowiki>{|</nowiki>
 
  <nowiki>{|</nowiki>
 +
 
| '''table start'''
 
| '''table start'''
 
|-
 
|-
|
+
|  
 
  <nowiki>|+</nowiki>
 
  <nowiki>|+</nowiki>
 +
 
| table '''caption,''' ''optional;'' only between '''table start''' and first '''table row'''
 
| table '''caption,''' ''optional;'' only between '''table start''' and first '''table row'''
 
|-
 
|-
|
+
|  
 
  <nowiki>|-</nowiki>
 
  <nowiki>|-</nowiki>
 +
 
| '''table row,''' ''optional on first row'' -- wiki engine assumes the first row
 
| '''table row,''' ''optional on first row'' -- wiki engine assumes the first row
 
|-
 
|-
|
+
|  
 
  <nowiki>!</nowiki>  
 
  <nowiki>!</nowiki>  
 +
 
| '''table header''' cell, ''optional.'' Consecutive '''table header''' cells may be added on same line separated by double marks (<code>!!</code>) or start on new lines, each with its own single mark (<code>!</code>).
 
| '''table header''' cell, ''optional.'' Consecutive '''table header''' cells may be added on same line separated by double marks (<code>!!</code>) or start on new lines, each with its own single mark (<code>!</code>).
|-  
+
|-
|
+
|  
 
  <nowiki>|</nowiki>
 
  <nowiki>|</nowiki>
 +
 
| '''table data''' cell, ''required!'' Consecutive '''table data''' cells may be added on same line separated by double marks (<code><nowiki>||</nowiki></code>) or start on new lines, each with its own single mark (<code><nowiki>|</nowiki></code>).
 
| '''table data''' cell, ''required!'' Consecutive '''table data''' cells may be added on same line separated by double marks (<code><nowiki>||</nowiki></code>) or start on new lines, each with its own single mark (<code><nowiki>|</nowiki></code>).
 
|-
 
|-
|
+
|  
 
  <nowiki>|}</nowiki>
 
  <nowiki>|}</nowiki>
| '''table end'''  
+
 
 +
| '''table end'''
 
|}
 
|}
*The above marks must '''start on a new line''' except the double <code>||</code> and <code>!!</code> for optionally adding consecutive cells to a line. However, blank spaces at the beginning of a line are ignored.
+
 
 +
*The above marks must '''start on a new line''' except the double <code>||</code> and <code>!!</code> for optionally adding consecutive cells to a line. However, blank spaces at the beginning of a line are ignored.  
 
*'''XHTML attributes.''' Each mark, except table end, optionally accepts one or more XHTML attributes. Attributes must be on the same line as the mark. Separate attributes from each other with a single space.  
 
*'''XHTML attributes.''' Each mark, except table end, optionally accepts one or more XHTML attributes. Attributes must be on the same line as the mark. Separate attributes from each other with a single space.  
**Cells and caption (<code>|</code> or <code>||</code>, <code>!</code> or <code>!!</code>, and <code>|+</code>) hold content. So separate any attributes from content with a single pipe (<code>|</code>). Cell content may follow on same line or on following lines.
+
**Cells and caption (<code>|</code> or <code>||</code>, <code>!</code> or <code>!!</code>, and <code>|+</code>) hold content. So separate any attributes from content with a single pipe (<code>|</code>). Cell content may follow on same line or on following lines.  
**Table and row marks (<code>{|</code> and <code>|-</code>) do not directly hold content. Do ''not'' add pipe (<code>|</code>) after their optional attributes. If you erroneously add a pipe after attributes for the table mark or row mark the parser will delete it ''and'' your final attribute if it was touching the erroneous pipe!
+
**Table and row marks (<code>{|</code> and <code>|-</code>) do not directly hold content. Do ''not'' add pipe (<code>|</code>) after their optional attributes. If you erroneously add a pipe after attributes for the table mark or row mark the parser will delete it ''and'' your final attribute if it was touching the erroneous pipe!  
*'''Content''' may (a) follow its cell mark on the same line after any optional XHTML attributes or (b) on lines below the cell mark. Content that uses wiki markup that itself needs to start on a new line, such as lists, headings, or nested tables, must be on its own new line.
+
*'''Content''' may (a) follow its cell mark on the same line after any optional XHTML attributes or (b) on lines below the cell mark. Content that uses wiki markup that itself needs to start on a new line, such as lists, headings, or nested tables, must be on its own new line.  
 
*'''Escaping''' to insert a pipe (<code>|</code>) character into a table use the &lt;nowiki&gt; markup
 
*'''Escaping''' to insert a pipe (<code>|</code>) character into a table use the &lt;nowiki&gt; markup
  
==Basics==
+
== Basics ==
The following table lacks borders and good spacing but shows the simplest wiki markup table structure.
+
 
 +
The following table lacks borders and good spacing but shows the simplest wiki markup table structure.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre>
+
! style="width: 50%;" | You get
 +
|-
 +
| <pre>{&#124;
 +
&#124;Orange
 +
&#124;Apple
 +
&#124;-
 +
&#124;Bread
 +
&#124;Pie
 +
&#124;-
 +
&#124;Butter
 +
&#124;Ice cream
 +
&#124;}
 +
</pre>
 +
|
 
{|
 
{|
|Orange
 
|Apple
 
 
|-
 
|-
|Bread
+
| Orange
|Pie
+
| Apple
 
|-
 
|-
|Butter
+
| Bread  
|Ice cream
+
| Pie
|}
+
</pre>
+
|
+
{|
+
|Orange
+
|Apple
+
|-
+
|Bread
+
|Pie
+
 
|-
 
|-
|Butter
+
| Butter  
|Ice cream  
+
| Ice cream
 
|}
 
|}
 +
 
|}
 
|}
  
The cells in the same row can be listed on one line separated by <code>||</code>.
+
The cells in the same row can be listed on one line separated by <code>||</code>.  
  
Extra spaces within cells in the wiki markup, as in the wiki markup below, do not affect the actual table rendering.
+
Extra spaces within cells in the wiki markup, as in the wiki markup below, do not affect the actual table rendering.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre>
+
! style="width: 50%;" | You get
 +
|-
 +
| <pre>{&#124;
 +
&#124;  Orange    &#124;&#124;  Apple  &#124;&#124;  more
 +
&#124;-
 +
&#124;  Bread    &#124;&#124;  Pie    &#124;&#124;  more
 +
&#124;-
 +
&#124;  Butter  &#124;&#124; Ice cream &#124;&#124;  and more
 +
&#124;}
 +
</pre>
 +
|
 
{|
 
{|
|  Orange    ||  Apple  ||  more
 
 
|-
 
|-
|   Bread    ||  Pie    ||  more
+
| Orange
|-
+
| Apple
|   Butter  || Ice cream ||  and more
+
| more
|}
+
</pre>
+
|
+
{|
+
|  Orange    ||  Apple  ||  more
+
 
|-
 
|-
|   Bread   |Pie     ||   more
+
| Bread  
 +
| Pie  
 +
| more
 
|-
 
|-
|   Butter   || Ice cream |and more
+
| Butter  
 +
| Ice cream  
 +
| and more
 
|}
 
|}
 +
 
|}
 
|}
  
=== Table headers ===
+
=== Table headers ===
Table headers can be created by using "<code>!</code>" instead of "<code>|</code>". Headers usually show up bold and centered by default.
+
 
 +
Table headers can be created by using "<code>!</code>" instead of "<code>|</code>". Headers usually show up bold and centered by default.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre>
+
! style="width: 50%;" | You get
{|
+
|-
 +
| <pre>{&#124;
 
! Item
 
! Item
 
! Amount
 
! Amount
 
! Cost
 
! Cost
|-
+
&#124;-
|Orange
+
&#124;Orange
|10
+
&#124;10
|7.00
+
&#124;7.00
|-
+
&#124;-
|Bread
+
&#124;Bread
|4
+
&#124;4
|3.00
+
&#124;3.00
|-
+
&#124;-
|Butter
+
&#124;Butter
|1
+
&#124;1
|5.00
+
&#124;5.00
|-
+
&#124;-
 
!Total
 
!Total
|
+
&#124;
|15.00
+
&#124;15.00
|}
+
&#124;}
</pre>
+
</pre>  
|
+
|  
 
{|
 
{|
! Item
+
|-
! Amount
+
! Item  
 +
! Amount  
 
! Cost
 
! Cost
 
|-
 
|-
|Orange
+
| Orange  
|10
+
| 10  
|7.00
+
| 7.00
 
|-
 
|-
|Bread
+
| Bread  
|4
+
| 4  
|3.00
+
| 3.00
 
|-
 
|-
|Butter
+
| Butter  
|1
+
| 1  
|5.00
+
| 5.00
 
|-
 
|-
!Total
+
! Total  
|
+
|  
|15.00
+
| 15.00
 
|}
 
|}
 +
 
|}
 
|}
  
===Caption===
+
=== Caption ===
A '''table caption''' can be added to the top of any table as follows.
+
 
 +
A '''table caption''' can be added to the top of any table as follows.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre>
+
! style="width: 50%;" | You get
{|
+
|+Food complements
+
 
|-
 
|-
|Orange
+
| <pre>{&#124;
|Apple
+
&#124;+Food complements
|-
+
&#124;-
|Bread
+
&#124;Orange
|Pie
+
&#124;Apple
|-
+
&#124;-
|Butter
+
&#124;Bread
|Ice cream  
+
&#124;Pie
|}
+
&#124;-
</pre>
+
&#124;Butter
|
+
&#124;Ice cream  
 +
&#124;}
 +
</pre>  
 +
|  
 
{|
 
{|
|+ Food complements
+
|+ Food complements  
 
|-
 
|-
|Orange
+
| Orange  
|Apple
+
| Apple
 
|-
 
|-
|Bread
+
| Bread  
|Pie
+
| Pie
 
|-
 
|-
|Butter
+
| Butter  
|Ice cream  
+
| Ice cream
 
|}
 
|}
 +
 
|}
 
|}
  
== XHTML attributes ==
+
== XHTML attributes ==
You can add XHTML attributes to tables. For the authoritative source on these, see [http://www.w3.org/TR/REC-html40/struct/tables.html the W3C's HTML 4.01 Specification page on tables].
+
  
=== Attributes on tables ===
+
You can add XHTML attributes to tables. For the authoritative source on these, see [http://www.w3.org/TR/REC-html40/struct/tables.html the W3C's HTML 4.01 Specification page on tables].
Placing attributes after the table start tag (<code>{|</code>) applies attributes to the entire table.
+
 
 +
=== Attributes on tables ===
 +
 
 +
Placing attributes after the table start tag (<code>{|</code>) applies attributes to the entire table.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre>
+
! style="width: 50%;" | You get
 +
|-
 +
| <pre>{&#124; border="1"
 +
&#124;Orange
 +
&#124;Apple
 +
&#124;12,333.00
 +
&#124;-
 +
&#124;Bread
 +
&#124;Pie
 +
&#124;500.00
 +
&#124;-
 +
&#124;Butter
 +
&#124;Ice cream
 +
&#124;1.00
 +
&#124;}
 +
</pre>
 +
|
 
{| border="1"
 
{| border="1"
|Orange
 
|Apple
 
|12,333.00
 
 
|-
 
|-
|Bread
+
| Orange
|Pie
+
| Apple
|500.00
+
| 12,333.00
 
|-
 
|-
|Butter
+
| Bread
|Ice cream
+
| Pie
|1.00
+
| 500.00
|}
+
</pre>
+
|
+
{| border="1"
+
|Orange
+
|Apple
+
|12,333.00
+
 
|-
 
|-
|Bread
+
| Butter  
|Pie
+
| Ice cream  
|500.00
+
| 1.00
|-
+
|Butter
+
|Ice cream
+
|1.00
+
 
|}
 
|}
 +
 
|}
 
|}
  
=== Attributes on cells ===
+
=== Attributes on cells ===
You can put attributes on individual '''cells'''. For example, numbers may look better aligned right.
+
 
 +
You can put attributes on individual '''cells'''. For example, numbers may look better aligned right.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre>
+
! style="width: 50%;" | You get
{| border="1"
+
|Orange
+
|Apple
+
|align="right" | 12,333.00
+
 
|-
 
|-
|Bread
+
| <pre>{&#124; border="1"
|Pie
+
&#124;Orange
|align="right" | 500.00
+
&#124;Apple
|-
+
&#124;align="right" &#124; 12,333.00
|Butter
+
&#124;-
|Ice cream
+
&#124;Bread
|align="right" | 1.00
+
&#124;Pie
|}
+
&#124;align="right" &#124; 500.00
</pre>
+
&#124;-
|
+
&#124;Butter
 +
&#124;Ice cream
 +
&#124;align="right" &#124; 1.00
 +
&#124;}
 +
</pre>  
 +
|  
 
{| border="1"
 
{| border="1"
|Orange
 
|Apple
 
|align="right"|12,333.00
 
 
|-
 
|-
|Bread
+
| Orange
|Pie
+
| Apple
|align="right"|500.00
+
| align="right" | 12,333.00
 
|-
 
|-
|Butter
+
| Bread
|Ice cream
+
| Pie
|align="right"|1.00
+
| align="right" | 500.00
 +
|-
 +
| Butter  
 +
| Ice cream  
 +
| align="right" | 1.00
 
|}
 
|}
 +
 
|}
 
|}
  
You can also use '''cell''' attributes when you are listing multiple '''cells''' on a single line. Note that the '''cells''' are separated by <code>||</code>, and within each '''cell''' the attribute(s) and value are separated by <code>|</code>.
+
You can also use '''cell''' attributes when you are listing multiple '''cells''' on a single line. Note that the '''cells''' are separated by <code>||</code>, and within each '''cell''' the attribute(s) and value are separated by <code>|</code>.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre>
+
! style="width: 50%;" | You get
{| border="1"
+
| Orange || Apple    || align="right" | 12,333.00
+
 
|-
 
|-
| Bread  || Pie      || align="right" | 500.00
+
| <pre>{&#124; border="1"
|-
+
&#124; Orange &#124;&#124; Apple    &#124;&#124; align="right" &#124; 12,333.00
| Butter || Ice cream || align="right" | 1.00
+
&#124;-
|}
+
&#124; Bread  &#124;&#124; Pie      &#124;&#124; align="right" &#124; 500.00
</pre>
+
&#124;-
|
+
&#124; Butter &#124;&#124; Ice cream &#124;&#124; align="right" &#124; 1.00
 +
&#124;}
 +
</pre>  
 +
|  
 
{| border="1"
 
{| border="1"
| Orange || Apple    || align="right" | 12,333.00
 
 
|-
 
|-
| Bread  || Pie      || align="right" | 500.00
+
| Orange
 +
| Apple
 +
| align="right" | 12,333.00
 
|-
 
|-
| Butter || Ice cream || align="right" | 1.00
+
| Bread
 +
| Pie
 +
| align="right" | 500.00
 +
|-
 +
| Butter
 +
| Ice cream  
 +
| align="right" | 1.00
 
|}
 
|}
 +
 
|}
 
|}
  
===Attributes on rows===
+
=== Attributes on rows ===
You can put attributes on individual '''rows''', too.
+
 
 +
You can put attributes on individual '''rows''', too.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre>
+
! style="width: 50%;" | You get
{| border="1"
+
|Orange
+
|Apple
+
|align="right"|12,333.00
+
 
|-
 
|-
|Bread
+
| <pre>{&#124; border="1"
|Pie
+
&#124;Orange
|align="right"|500.00
+
&#124;Apple
|- style="font-style:italic; color:green;"
+
&#124;align="right"&#124;12,333.00
|Butter
+
&#124;-
|Ice cream
+
&#124;Bread
|align="right"|1.00
+
&#124;Pie
|}
+
&#124;align="right"&#124;500.00
</pre>
+
&#124;- style="font-style:italic; color:green;"
|
+
&#124;Butter
 +
&#124;Ice cream
 +
&#124;align="right"&#124;1.00
 +
&#124;}
 +
</pre>  
 +
|  
 
{| border="1"
 
{| border="1"
|Orange
 
|Apple
 
|align="right"|12,333.00
 
 
|-
 
|-
|Bread
+
| Orange
|Pie
+
| Apple
|align="right"|500.00
+
| align="right" | 12,333.00
|- style="font-style:italic; color:green;"
+
|-
|Butter
+
| Bread  
|Ice cream
+
| Pie  
|align="right"|1.00
+
| align="right" | 500.00
 +
|- style="font-style: italic; color: green;"
 +
| Butter  
 +
| Ice cream  
 +
| align="right" | 1.00
 
|}
 
|}
 +
 
|}
 
|}
  
===HTML colspan and rowspan===
+
=== HTML colspan and rowspan ===
  
You can use HTML '''colspan''' and '''rowspan''' attributes on cells for advanced layout.
+
You can use HTML '''colspan''' and '''rowspan''' attributes on cells for advanced layout.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre>
+
! style="width: 50%;" | You get
{| border="1"
+
!colspan="6"|Shopping List
+
 
|-
 
|-
|rowspan="2"|Bread & Butter
+
| <pre>{&#124; border="1"
|Pie
+
!colspan="6"&#124;Shopping List
|Buns
+
&#124;-
|Danish
+
&#124;rowspan="2"&#124;Bread &amp; Butter
|colspan="2"|Croissant
+
&#124;Pie
|-
+
&#124;Buns
|Cheese
+
&#124;Danish
|colspan="2"|Ice cream
+
&#124;colspan="2"&#124;Croissant
|Butter
+
&#124;-
|Yoghurt
+
&#124;Cheese
|}
+
&#124;colspan="2"&#124;Ice cream
</pre>
+
&#124;Butter
|
+
&#124;Yoghurt
 +
&#124;}
 +
</pre>  
 +
|  
 
{| border="1"
 
{| border="1"
!colspan="6"|Shopping List
 
 
|-
 
|-
|rowspan="2"|Bread & Butter
+
! colspan="6" | Shopping List
|Pie
+
|Buns
+
|Danish
+
|colspan="2"|Croissant
+
 
|-
 
|-
|Cheese
+
| rowspan="2" | Bread &amp; Butter
|colspan="2"|Ice cream
+
| Pie
|Butter
+
| Buns
|Yoghurt
+
| Danish
 +
| colspan="2" | Croissant
 +
|-
 +
| Cheese  
 +
| colspan="2" | Ice cream  
 +
| Butter  
 +
| Yoghurt
 
|}
 
|}
 +
 
|}
 
|}
  
===With HTML attributes and CSS styles===
+
=== With HTML attributes and CSS styles ===
CSS style attributes can be added with or without other HTML attributes.
+
 
 +
CSS style attributes can be added with or without other HTML attributes.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre style="white-space:-moz-pre-wrap; white-space:-pre-wrap; white-space:-o-pre-wrap; white-space:pre-wrap; word-wrap:break-word; word-break:break-all;">
+
! style="width: 50%;" | You get
{| style="color:green; background-color:#ffffcc;" cellpadding="20" cellspacing="0" border="1"
+
|Orange
+
|Apple
+
 
|-
 
|-
|Bread
+
| <pre style="white-space: pre-wrap; word-wrap: break-word;">{&#124; style="color:green; background-color:#ffffcc;" cellpadding="20" cellspacing="0" border="1"
|Pie
+
&#124;Orange
 +
&#124;Apple
 +
&#124;-
 +
&#124;Bread
 +
&#124;Pie
 +
&#124;-
 +
&#124;Butter
 +
&#124;Ice cream
 +
&#124;}
 +
</pre>
 +
|
 +
{| cellspacing="0" cellpadding="20" border="1" style="color: green; background-color: rgb(255, 255, 204);"
 
|-
 
|-
|Butter
+
| Orange  
|Ice cream
+
| Apple
|}
+
</pre>
+
|
+
{| style="color:green; background-color:#ffffcc;" cellpadding="20" cellspacing="0" border="1"
+
|Orange
+
|Apple
+
 
|-
 
|-
|Bread
+
| Bread  
|Pie
+
| Pie
 
|-
 
|-
|Butter
+
| Butter  
|Ice cream  
+
| Ice cream
 
|}
 
|}
 +
 
|}
 
|}
  
'''Attributes''' can be added to the caption and headers as follows.
+
'''Attributes''' can be added to the caption and headers as follows.  
  
 
{| cellspacing="0" border="1"
 
{| cellspacing="0" border="1"
!style="width:50%"|You type
 
!style="width:50%"|You get
 
 
|-
 
|-
|
+
! style="width: 50%;" | You type
<pre style="white-space:-moz-pre-wrap; white-space:-pre-wrap; white-space:-o-pre-wrap; white-space:pre-wrap; word-wrap:break-word; word-break:break-all;">
+
! style="width: 50%;" | You get
{| border="1" cellpadding="20" cellspacing="0"
+
|+ align="bottom" style="color:#e76700;" |''Food complements''
+
 
|-
 
|-
|Orange
+
| <pre style="white-space: pre-wrap; word-wrap: break-word;">{&#124; border="1" cellpadding="20" cellspacing="0"
|Apple
+
&#124;+ align="bottom" style="color:#e76700;" &#124;''Food complements''
 +
&#124;-
 +
&#124;Orange
 +
&#124;Apple
 +
&#124;-
 +
&#124;Bread
 +
&#124;Pie
 +
&#124;-
 +
&#124;Butter
 +
&#124;Ice cream
 +
&#124;}
 +
</pre>
 +
|
 +
{| cellspacing="0" cellpadding="20" border="1"
 +
|+ ''Food complements''
 
|-
 
|-
|Bread
+
| Orange
|Pie
+
| Apple
 
|-
 
|-
|Butter
+
| Bread
|Ice cream
+
| Pie
|}
+
</pre>
+
|
+
{| border="1" cellpadding="20" cellspacing="0"
+
|+ align="bottom" style="color:#e76700;" |''Food complements''
+
 
|-
 
|-
|Orange
+
| Butter  
|Apple
+
| Ice cream
|-
+
|Bread
+
|Pie
+
|-
+
|Butter
+
|Ice cream  
+
 
|}
 
|}
 +
 
|}
 
|}
  
==Caveats==
+
== Caveats ==
===Negative numbers===
+
 
If you start a cell on a new line with a negative number with a minus sign (or a parameter that evaluates to a negative number), your table can get broken, because the characters <code>|-</code> will be parsed as the wiki markup for table row, not table cell. To avoid this, insert a space before the value (<code>| -6</code>) or use in-line cell markup (<code>|| -6</code>).
+
=== Negative numbers ===
===CSS vs Attributes===
+
 
Table borders specified through CSS rather than the border attribute will render incorrectly in a small subset of text browsers.
+
If you start a cell on a new line with a negative number with a minus sign (or a parameter that evaluates to a negative number), your table can get broken, because the characters <code>|-</code> will be parsed as the wiki markup for table row, not table cell. To avoid this, insert a space before the value (<code>| -6</code>) or use in-line cell markup (<code>|| -6</code>).  
 +
 
 +
=== CSS vs Attributes ===
 +
 
 +
Table borders specified through CSS rather than the border attribute will render incorrectly in a small subset of text browsers.  
 +
 
 +
<br>
  
{{Languages}}
+
[[Category:Help]]
[[Category:Help|Tables]]
+

Latest revision as of 18:12, 3 June 2010

Tables may be authored in wiki pages using either XHTML table elements directly, or using wikicode formatting to define the table. XHTML table elements and their use are well described on various web pages and will not be discussed here. The benefit of wikicode is that the table is constructed of character symbols which tend to make it easier to perceive the table structure in the article editing view compared to XHTML table elements.

As a general rule, it is best to avoid using a table unless you need one. Table markup often complicates page editing.

Contents

[edit] Wiki table markup summary

{|
table start
|+
table caption, optional; only between table start and first table row
|-
table row, optional on first row -- wiki engine assumes the first row
! 
table header cell, optional. Consecutive table header cells may be added on same line separated by double marks (!!) or start on new lines, each with its own single mark (!).
|
table data cell, required! Consecutive table data cells may be added on same line separated by double marks (||) or start on new lines, each with its own single mark (|).
|}
table end
  • The above marks must start on a new line except the double || and !! for optionally adding consecutive cells to a line. However, blank spaces at the beginning of a line are ignored.
  • XHTML attributes. Each mark, except table end, optionally accepts one or more XHTML attributes. Attributes must be on the same line as the mark. Separate attributes from each other with a single space.
    • Cells and caption (| or ||, ! or !!, and |+) hold content. So separate any attributes from content with a single pipe (|). Cell content may follow on same line or on following lines.
    • Table and row marks ({| and |-) do not directly hold content. Do not add pipe (|) after their optional attributes. If you erroneously add a pipe after attributes for the table mark or row mark the parser will delete it and your final attribute if it was touching the erroneous pipe!
  • Content may (a) follow its cell mark on the same line after any optional XHTML attributes or (b) on lines below the cell mark. Content that uses wiki markup that itself needs to start on a new line, such as lists, headings, or nested tables, must be on its own new line.
  • Escaping to insert a pipe (|) character into a table use the <nowiki> markup

[edit] Basics

The following table lacks borders and good spacing but shows the simplest wiki markup table structure.

You type You get
{|
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}
Orange Apple
Bread Pie
Butter Ice cream

The cells in the same row can be listed on one line separated by ||.

Extra spaces within cells in the wiki markup, as in the wiki markup below, do not affect the actual table rendering.

You type You get
{|
|  Orange    ||   Apple   ||   more
|-
|   Bread    ||   Pie     ||   more
|-
|   Butter   || Ice cream ||  and more
|}
Orange Apple more
Bread Pie more
Butter Ice cream and more

[edit] Table headers

Table headers can be created by using "!" instead of "|". Headers usually show up bold and centered by default.

You type You get
{|
! Item
! Amount
! Cost
|-
|Orange
|10
|7.00
|-
|Bread
|4
|3.00
|-
|Butter
|1
|5.00
|-
!Total
|
|15.00
|}
Item Amount Cost
Orange 10 7.00
Bread 4 3.00
Butter 1 5.00
Total 15.00

[edit] Caption

A table caption can be added to the top of any table as follows.

You type You get
{|
|+Food complements
|-
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}
Food complements
Orange Apple
Bread Pie
Butter Ice cream

[edit] XHTML attributes

You can add XHTML attributes to tables. For the authoritative source on these, see the W3C's HTML 4.01 Specification page on tables.

[edit] Attributes on tables

Placing attributes after the table start tag ({|) applies attributes to the entire table.

You type You get
{| border="1"
|Orange
|Apple
|12,333.00
|-
|Bread
|Pie
|500.00
|-
|Butter
|Ice cream
|1.00
|}
Orange Apple 12,333.00
Bread Pie 500.00
Butter Ice cream 1.00

[edit] Attributes on cells

You can put attributes on individual cells. For example, numbers may look better aligned right.

You type You get
{| border="1"
|Orange
|Apple
|align="right" | 12,333.00
|-
|Bread
|Pie
|align="right" | 500.00
|-
|Butter
|Ice cream
|align="right" | 1.00
|}
Orange Apple 12,333.00
Bread Pie 500.00
Butter Ice cream 1.00

You can also use cell attributes when you are listing multiple cells on a single line. Note that the cells are separated by ||, and within each cell the attribute(s) and value are separated by |.

You type You get
{| border="1"
| Orange || Apple     || align="right" | 12,333.00
|-
| Bread  || Pie       || align="right" | 500.00
|-
| Butter || Ice cream || align="right" | 1.00
|}
Orange Apple 12,333.00
Bread Pie 500.00
Butter Ice cream 1.00

[edit] Attributes on rows

You can put attributes on individual rows, too.

You type You get
{| border="1"
|Orange
|Apple
|align="right"|12,333.00
|-
|Bread
|Pie
|align="right"|500.00
|- style="font-style:italic; color:green;"
|Butter
|Ice cream
|align="right"|1.00
|}
Orange Apple 12,333.00
Bread Pie 500.00
Butter Ice cream 1.00

[edit] HTML colspan and rowspan

You can use HTML colspan and rowspan attributes on cells for advanced layout.

You type You get
{| border="1"
!colspan="6"|Shopping List
|-
|rowspan="2"|Bread & Butter
|Pie
|Buns
|Danish
|colspan="2"|Croissant
|-
|Cheese
|colspan="2"|Ice cream
|Butter
|Yoghurt
|}
Shopping List
Bread & Butter Pie Buns Danish Croissant
Cheese Ice cream Butter Yoghurt

[edit] With HTML attributes and CSS styles

CSS style attributes can be added with or without other HTML attributes.

You type You get
{| style="color:green; background-color:#ffffcc;" cellpadding="20" cellspacing="0" border="1"
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}
Orange Apple
Bread Pie
Butter Ice cream

Attributes can be added to the caption and headers as follows.

You type You get
{| border="1" cellpadding="20" cellspacing="0"
|+ align="bottom" style="color:#e76700;" |''Food complements''
|-
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}
Food complements
Orange Apple
Bread Pie
Butter Ice cream

[edit] Caveats

[edit] Negative numbers

If you start a cell on a new line with a negative number with a minus sign (or a parameter that evaluates to a negative number), your table can get broken, because the characters |- will be parsed as the wiki markup for table row, not table cell. To avoid this, insert a space before the value (| -6) or use in-line cell markup (|| -6).

[edit] CSS vs Attributes

Table borders specified through CSS rather than the border attribute will render incorrectly in a small subset of text browsers.


Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox