Help:Other Table Formats
Contents |
[edit] Other table syntax
Other types of table syntax that MediaWiki supports:
- XHTML
- HTML & wiki-<td> syntax (Do not use)
All three are supported by MediaWiki and create (currently) valid HTML output, but the pipe syntax is the simplest. Also, HTML & wiki-<td> syntax (i.e., unclosed <td> and <tr> tags) will not necessarily remain browser-supported in the upcoming future, especially on handheld internet-accessible devices.
See also Help:Table Editing. Note that some HTML elements such as the thead
, tbody
, tfoot
, colgroup
, and col
elements are currently not supported in W:MediaWiki.
[edit] Comparison of table syntax
XHTML | HTML & Wiki-td | Wiki-pipe | |||||||
---|---|---|---|---|---|---|---|---|---|
Table | <table></table> | <table></table> | {| |} | ||||||
Caption | <caption>caption</caption> | <caption>caption</caption> | |+ caption | ||||||
Row | <tr></tr> | <tr> | |- | ||||||
Data cell |
<td>cell1</td> |
<td>cell1 |
| cell1 | cell2 | ||||||
Data cell | <td>cell1</td> <td>cell2</td> <td>cell3</td> | <td>cell1 <td>cell2 <td>cell3 | | cell1 || cell2 || cell3 | ||||||
Header cell | <th>heading</th> | <th>heading | ! heading | ||||||
Sample table |
| ||||||||
<table> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>3</td> <td>4</td> </tr> </table> | <table> <tr> <td> 1 <td> 2 <tr> <td> 3 <td> 4 </table> | {| | 1 || 2 |- | 3 || 4 |} | |||||||
Sample table |
| ||||||||
<table> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> </tr> </table> | <table> <tr> <td> 1 <td> 2 <tr> <td> 3 <td> 4 <tr> <td> 5 <td> 6 </table> | {| | 1 || 2 |- | 3 || 4 |- | 5 || 6 |} | |||||||
Pros |
|
|
| ||||||
Cons |
|
|
| ||||||
XHTML | HTML & Wiki-td | Wiki-pipe |
See also Template talk:For#Tables.
[edit] Pipe syntax in terms of the HTML produced
The pipe syntax, developed by Magnus Manske, substitutes pipes (|) for HTML. There is an on-line script which converts html tables to pipe syntax tables.
The pipes must start at the beginning of a new line, except when separating parameters from content or when using ||
to separate cells on a single line. The parameters are optional.
[edit] Tables
A table is defined by {| ''params'' |} which equals <table ''params''>Insert non-formatted text here </table>
[edit] Rows
<tr> tags will be generated automatically for the first row. To start a new row, use
|-
which results in
<tr>
Parameters can be added like this:
|- params
which results in
<tr params>
Note:
- <tr> tags will be automatically opened at the first <td> equivalent
- <tr> tags will be automatically closed at <tr> and </table> equivalents
[edit] Cells
Cells are generated either like this:
|cell1 |cell2 |cell3
or like this:
|cell1||cell2||cell3
which both equal
<td>cell1</td><td>cell2</td><td>cell3</td>
so "||" equals "newline" + "|"
Parameters in cells can be used like this:
|params|cell1||params|cell2||params|cell3
which will result in
<td params>cell1</td> <td params>cell2</td> <td params>cell3</td>
[edit] Headers
Functions the same way as TD, except "!" is used instead of the opening "|". "!!" can be used instead of "||". Parameters still use "|", though! Example:
!params|cell1
[edit] Captions
A <caption> tag is created by
|+ Caption
which generates
<caption>Caption</caption>
You can also use parameters:
|+ params|Caption
which will generate
<caption params>Caption</caption>