From Governance Wiki
[edit] Simple tables
A simple table will just have a header row, and then rows full of data below.
| Description
| You type…
| You get…
|
| Simple table with header row and three rows of data. Header cells start with an "!", while normal cells start with a "|".
| {|{{prettytable}}
! Header 1
! Header 2
! Header 3
|-
| Foo
| Bar
| Baz
|-
| Fiddle
| Middle
| Tiddle
|-
| Fi
| Fo
| Fum
|}
|
| Header 1
| Header 2
| Header 3
|
| Foo
| Bar
| Baz
|
| Fiddle
| Middle
| Tiddle
|
| Fi
| Fo
| Fum
|
|
| The same table, but with the cell data compressed so that the wikicode occupies less space.
| {|{{prettytable}}
! Header 1 !! Header 2 !! Header 3
|-
| Foo || Bar || Baz
|-
| Fiddle || Middle || Tiddle
|-
| Fi || Fo || Fum
|}
|
| Header 1 | Header 2 | Header 3
|
| Foo | Bar | Baz
|
| Fiddle | Middle | Tiddle
|
| Fi | Fo | Fum
|
|
| Table with a caption, describing what the table shows. There can only be one caption per table, and its row starts with a "|+".
| {|{{prettytable}}
|+ Explanatory table demonstrating wikicode.
! Header 1 !! Header 2 !! Header 3
|-
| Foo || Bar || Baz
|-
| Fiddle || Middle || Tiddle
|-
| Fi || Fo || Fum
|}
|
Explanatory table demonstrating wikicode.
| Header 1 | Header 2 | Header 3
|
| Foo | Bar | Baz
|
| Fiddle | Middle | Tiddle
|
| Fi | Fo | Fum
|
|
| You can also have header cells in each row, for example, if the first cell of each row is a heading for that row. Such header cells still begin with a "!".
| {|{{prettytable}}
! Header 1
! Header 2
! Header 3
|-
! Foo
| Bar
| Baz
|-
! Fiddle
| Middle
| Tiddle
|-
! Fi
| Fo
| Fum
|}
|
| Header 1
| Header 2
| Header 3
|
| Foo
| Bar
| Baz
|
| Fiddle
| Middle
| Tiddle
|
| Fi
| Fo
| Fum
|
|
[edit] prettytable
You may have noticed the {{prettytable}} template at the top of each of those tables. This template should be put at the top of every data table you create, as it styles the table correctly, and allows you to do some nice things.
[edit] Sortable tables
If your table contains a lot of numeric information, or things which the reader may want to look at in alphabetic order, you can put the "|sortable=1" parameter into the {{prettytable}} at the top of your table, and headings at the top of the table will acquire sort buttons. For example:
Explanatory table demonstrating sorting.
| Alphabetic | Numeric | Random
|
| A | 65 | Foo
|
| C | 12 | Bar
|
| B | 53 | Baz
|
[edit] Narrow/Floated tables
By default, {{prettytable}} will make your table occupy the full width of the page (or its container). In most cases, this is what you want, but if you're floating a table off to one side, you may want it to occupy as little width as possible. For this, you can use the "|notwide=1" parameter for {{prettytable}}, but if you're floating the table, you can instead use the "|float=left" or "|float=right" parameters, which will implicitly make the table narrow.
However, there may be other cases where you're not floating a table, but you do want it narrow. In such cases, put the "|notwide=1" parameter into the {{prettytable}} at the top of your table.
[edit] Text centering
Usually, text should be left-aligned in a table, but if (for example), the table contains lots of images, which would look better center-aligned, put the "|text center=1" parameter into the {{prettytable}} at the top of your table, and all the contents will be center-aligned.
[edit] More flexibility
If you know CSS, or want more information about the parameters for {{prettytable}}, they're described in detail in its documentation.
Tables can be used for displaying data, and also for creating box-type designs for pages on your Wikia.
Some HTML table tags are currently supported by MediaWiki, but there is no guarantee these will not be deprecated. For this reason, you are advised to use the wiki syntax, which is described on this page.
Note, the following information does not apply to the WYSIWYG mode of the new editor, though you will notice the syntax when in source mode
Markup
|
| XHTML
| Wiki syntax
|
| Table
| <table></table>
| {| params
|}
|
| Caption
| <caption></caption>
| |+ caption
|
| Row
| <tr></tr>
| |- params
|
| Data cell
| <td>cell1</td>
<td>cell2</td>
|
| cell1
| cell2
|
| Data cell
| <td>cell1</td> <td>cell2</td> <td>cell3</td>
| |cell1||cell2||cell3
|
| Header cell
| <th></th>
| ! heading
|
See also MetaWikipedia:Help:Table on Meta-Wiki for more markup information, including how to make tables sortable.
Sample table
| XHTML
| Wiki syntax
|
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
|
{|
| 1 || 2
|-
| 3 || 4
|}
|
Notes
- The entire table begins with
{| and ends with the required |}.
- A caption is a succinct way to describe your table, and can be included with
|+ on the line after {|.
- Table rows are horizontal groups of cells in the table. A row begins with
|- and ends at the next row.
- Table headings are cells with headings in them, and are often rendered in a bold font. They begin with
!. Note that parameters are still separated from the actual content of the cell with |, however
- Table data cells fill out the rest of the table. A cell begins with
| or || and ends at the next cell.
Each row must have the same number of cells as the other rows, so that the number of columns in the table remains consistent (unless there are cells which span several columns or rows, but this is not discussed here). For empty cells, use the non-breaking space as content to ensure that the cells are displayed.
Complex layout (made simple)
This advanced example shows some of the options available for making tables. You can play with these settings in your own table to see what effect they have. Not all of these techniques may be appropriate in all cases; just because you can add colored backgrounds, for example, doesn't mean it's always a good idea. Try to keep the markup in your tables relatively simple — remember, other people are going to be editing the page too.
An example layout
| First header
| Second header
|
| upper left
|
| right side
|
| lower left
| lower middle
|
|
|
|
Welcome to the twin cities
|
Your table code reflect the table structure. Although it is possible to compose complex layout as one table, it is generally not advisable. For simplicity, it is best to split the layout into small units.
Split it up
While you can nest table
| layout
| code
|
An example layout
| First header
| Second header
|
| upper left
|
| right side
|
| lower left
| lower middle
|
A table in a table
|
|
|
|
{| border="1" cellpadding="5" cellspacing="0" style="border-collapse:collapse;" width="330"
|+'''An example layout'''
|-
! First header
! colspan="2" | Second header
|-
| upper left
|
| rowspan=2 | right side
|-
| | lower left
| | lower middle
|-
| colspan="3" align="center" |
{| border="0"
|+''A table in a table''
|-
|| [[File:Wiki.png]]
|| [[File:Wiki.png]]
|}
|}
|
It may be better to split the tables up:
| layout
| code
|
An example layout
| First header
| Second header
|
| upper left
|
| right side
|
| lower left
| lower middle
|
|
{| border="1" cellpadding="5" cellspacing="0" width="330" style="border-collapse:collapse;"
|+'''An example layout'''
|-
! First header
! colspan="2" | Second header
|-
| upper left
|
| rowspan=2 | right side
|-
| | lower left
| | lower middle
|}
{| style="border:1px solid; border-top:none; width:330px;"
|-
|| [[File:Wiki.png]]
|| [[File:Wiki.png]]
|}
|
Don't use table for simple box
Table code should be used for tables only. For simple boxes, use <div></div> instead. For example, instead of:
| layout
| code
|
|
|
|
Welcome to the twin cities
|
|
{| style="border:1px solid; border-top:none; width:330px;"
|-
|| [[File:Wiki.png]]
|| [[File:Wiki.png]]
|-
| align="center" colspan="2" style="border-top:1px solid red;"|
Welcome to the twin cities
|}
|
You may use
| layout
| code
|
|
|
|
Welcome to the twin cities
|
|
{| style="border:1px solid; border-top:none; width:330px;"
|-
|| [[File:Wiki.png]]
|| [[File:Wiki.png]]
|-
| align="center" colspan="2"|
<div style="border:1px solid red;">Welcome to the twin cities</div>
|}
|
The complete code
An example layout
| First header
| Second header
|
| upper left
|
| right side
|
| lower left
| lower middle
|
|
|
|
Welcome to the twin cities
|
{| border="1" cellpadding="5" cellspacing="0" width="330" style="border-collapse:collapse;"
|+'''An example layout'''
|-
! style="background:#efefef; color:#000;" | First header
! colspan="2" style="background:#ffdead; color:#000;" | Second header
|-
| upper left
|
| rowspan=2 | right side
|-
| | lower left
| | lower middle
|}
{| style="border:1px solid; border-top:none; width:330px;"
|-
|| [[File:Wiki.png]]
|| [[File:Wiki.png]]
|-
| align="center" colspan="2"|
<div style="border:1px solid red;">Welcome to the twin cities</div>
|}
See also
- MetaWikipedia:Help:Table on Meta-Wiki, upon which this page was based. This page has more detailed information, and also has a number of external links to sites offering HTML-to-wiki-conversion.
- Help:Editing
External links