Help:Tables
From Teach And Discover Wiki
This page gives you information about syntax to build wiki-tables in MediaWiki.
Spreadsheet to wiki table format
To convert from spreadsheets such as Gnumeric, MS Excel or OpenOffice.org Calc, go here.
Using the toolbar
You can use the Mediawiki edit toolbar to create tables on wikipedia, and some wikimedia projects. It is helpful to generate the necessary codings. However on many MediaWiki wikis (and by default) the table tool is not available.
Use the first button on the right of the toolbar to insert a table when editing a page.
By default, it includes the following text:
{| class="wikitable"
|-
! header 1
! header 2
! header 3
|-
| row 1, cell 1
| row 1, cell 2
| row 1, cell 3
|-
| row 2, cell 1
| row 2, cell 2
| row 2, cell 3
|}
Pipe syntax tutorial
| Column heading 1 | Column heading 2 | Column heading 3 |
|---|---|---|
| Row heading 1 | Cell 2 | Cell 100 |
| Row heading A | Cell B | Cell C |
Although HTML table syntax also works, special wikicode can be used as a shortcut to create a table. The pipe (vertical bar) codes function exactly the same as HTML table markup, so a knowledge of HTML table code will help in understanding pipe code. The shortcuts are as follows:
- The entire table is encased with curly brackets and a vertical bar character (a pipe). So use
{|to begin a table, and|}to end it. Each one needs to be on its own line:
{| table code goes here |}
- An optional table caption is included with a line starting with a vertical bar and plus sign "
|+" and the caption after it:
{|
|+ caption
table code goes here
|}
- To start a new table row, type a vertical bar and a hyphen on its own line: "
|-". The codes for the cells in that row will start on the next line.
{|
|+ The table's caption
|-
cell code goes here
|-
cell code goes here
|}
- Type the codes for each table cell in the next row, starting with a bar:
{|
|+ The table's caption
|-
| cell codes go here
|-
| cells in the next row go here
| more cells in the same row here
|}
- Cells can be separated with either a new line and new bar, or by a double bar "||" on the same line. Both produce the same output:
{|
|+ The table's caption
|-
|Cell 1 || Cell 2 || Cell 3
|-
|Cell A
|Cell B
|Cell C
|}
- If you use single bars, then what might appear to be the first cell is in fact a format modifier applied to the cell, and the rest of your "cells" will be merged into one:
{| border="1"
|-
|format modifier (not displayed)|These all |(including the pipes)|go into |the first cell
|-
|}
which is probably not what you want:
| These all |(including the pipes)|go into |the first cell |
However, the format modifier is useful:
{| border="1"
|-
|Cell 1 (no modifier - not aligned)
|-
|align="right" |Cell 2 (right aligned)
|-
|}
| Cell 1 (no modifier - not aligned) |
| Cell 2 (right aligned) |
Just remember: no more than 2 single pipes on a line!
- a row of column headings is identified by using "!" instead of "|", and using "!!" instead of "||". Header cells typically render differently from regular cells, depending on the browser. They are often rendered in a bold font and centered.
{|
|+ The table's caption
! Column heading 1 !! Column heading 2 !! Column heading 3
|-
|Cell 1 || Cell 2 || Cell 3
|-
|Cell A
|Cell B
|Cell C
|}
- the first cell of a row is identified as row heading by starting the line with "!" instead of "|", and starting subsequent data cells on a new line.
{|
|+ The table's caption
! Column heading 1 !! Column heading 2 !! Column heading 3
|-
! Row heading 1
| Cell 2 || Cell 3
|-
! Row heading A
|Cell B
|Cell C
|}
- Optional parameters can modify the behavior of cells, rows, or the entire table. For instance, a border could be added to the table:
{| border="1"
|+ The table's caption
! Column heading 1 !! Column heading 2 !! Column heading 3
|-
! Row heading 1
| Cell 2 || Cell 3
|-
! Row heading A
|Cell B
|Cell C
|}
The final table would display like this:
The table's caption Column heading 1 Column heading 2 Column heading 3 Row heading 1 Cell 2 Cell 3 Row heading A Cell B Cell C
The table parameters and cell parameters are the same as in HTML, see [1] and Table (HTML). However, the thead, tbody, tfoot, colgroup, and col elements are currently not supported in MediaWiki.
A table can be useful even if none of the cells have content. For example, the background colors of cells can be changed with cell parameters, making the table into a diagram, like Template:mlm. An "image" in the form of a table is much more convenient to edit than an uploaded image.
Each row must have the same number of cells as the other rows, so that the number of columns in the table remains consistent. For empty cells, use the non-breaking space as content to ensure that the cells are displayed. To show a visible pipe in a cell, use <nowiki>|</nowiki> or |.
With colspan and rowspan cells can span several columns or rows, see the Mélange example below. However, this has the disadvantage that sorting does not work properly anymore.
