Help:Table

Pipe syntax
Although HTML table syntax also works, special wikicode can be used to create a table, as follows:


 * The entire table begins with a line " optional table parameters " and ends with the line " ".
 * An optional table caption is included with a line " caption " after " ".
 * The code for a table row consists of the line " optional table parameters ", and, starting on a new line, the codes for the cells in the row, separated by newline or "|"
 * Table data are the codes for the cells; cell code is of the form "| value " or "| cell parameters | value "
 * a row of column headings is identified by using "!" instead of "|", except for the separator between a cell parameter and a value; the difference with a normal row depends on the browser, column headings are often rendered in a bold font.
 * 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 parameters and cell parameters are the same as in HTML, see  and  HTML element#Tables. However, the,  ,  ,  , and   elements are currently not supported in MediaWiki.

A table can be useful even if none of the cells have content, notably because with the use of background colors of cells the table can be a diagram, see e.g. m:Template talk:Square 8x8 pentomino example. 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 (unless there are cells which span several columns or rows, see colspan and rowspan in Mélange example below). For empty cells, use the non-breaking space  as content to ensure that the cells are displayed.

Simple example
and

both generate

Source code


Appearance


Color; scope of parameters
Two ways of specifying color of text and background for a single cell are as follows:

gives

As shown "font" works for one cell only, even without end tag: the end tag is produced by the system.

Like other parameters, colors can also be specified for a whole row or the whole table; parameters for a row override the value for the table, and those for a cell override those for a row:

gives

The HTML 4.01 specification defines sixteen named colors, here shown with hexadecimal values:

See web colors.

Width, height
The width and height of the whole table can be specified, as well as the height of a row. To specify the width of a column one can specify the width of an arbitrary cell in it. If the width is not specified for all columns, and/or the height is not specified for all rows, then there is some ambiguity, and the result depends on the browser.

gives

Positioning
One can position the table itself, and all contents in a row, and contents in a cell, but not with a single parameter all contents in the table, see m:Template talk:Table demo. Do not, under any circumstances, use "float" to position a table. It will break page rendering at large font sizes.

M&eacute;lange
Here's a more advanced example, showing some more options available for making up 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 article too! This example should give you an idea of what is possible, though.

Source code


Appearance


Advanced example
Note the floating table to the right.

Nested table
gives a nested table

{| border=1
 * &alpha;
 * align="center" | cell2


 * valign="bottom" | the original table again
 * }

Nested tables have to start on a new line.

Other table syntax
Other types of table syntax that MediaWiki supports:
 * 1) XHTML
 * 2) HTML and wiki  syntax

All three are supported by MediaWiki and create (currently) valid HTML output, but the pipe syntax is the simplest, except perhaps for people who are already familiar with HTML. Also, HTML and wiki  syntax will not necessarily remain browser-supported in the upcoming future, especially on handheld internet-accessible devices.

See also HTML element#Tables. Note however that the,  ,  ,  , and   elements are currently not supported in MediaWiki.

Comparison
Sample table

Pros Can be previewed/debugged with any XHTML editor

Can be formatted for easier reading

Well-known

Can be previewed/debugged with any HTML editor

Can be formatted for easier reading

Well-known

Takes less space than XHTML Easy to write

Easy to read

Takes little space

Cons Tedious

Takes a lot of space

Difficult to read quickly

Confusing, especially for people with little HTML experience

Poorly formed

Poorly delimited

Generally odd looking

May not have browser support in future

Unfamiliar syntax

Rigid structure

Cannot be indented

Text (as in HTML tags) may be easier for some people to read than series of pipes, plus signs, exclamation marks, etc.

XHTML HTML &amp; Wiki-td Wiki-pipe

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.

Tables
A table is defined by which equals and, or the first parameter gets ignored.

Rows
<tr&gt; tags will be generated automatically for the first row. To start a new row, use |- which results in &lt;tr&gt; Parameters can be added like this: |- params which results in &lt;tr params&gt;

Note:
 * <tr&gt; tags will be automatically opened at the first <td&gt; equivalent
 * <tr&gt; tags will be automatically closed at <tr&gt; and </table&gt; equivalents

Cells
Cells are generated either like this: |cell1 |cell2 |cell3 or like this: |cell1||cell2||cell3 which both equal <td&gt;cell1</td&gt;<td&gt;cell2</td&gt;<td&gt;cell3</td&gt; so "||" equals "newline" + "|"

Parameters in cells can be used like this: |params|cell1||params|cell2||params|cell3 which will result in <td params&gt;cell1 <td params&gt;cell2 <td params&gt;cell3

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

Captions
A <caption&gt; tag is created by |+ Caption which generates &lt;caption&gt;Caption&lt;/caption&gt; You can also use parameters: |+ params|Caption which will generate &lt;caption params&gt;Caption&lt;/caption&gt;

Text next to a table
(To see demonstrated effects, you may have to increase or decrease the fontsize setting of the browser; also you can vary the width of the browser window.)

You can use align=right, text after the table code appears to the left of the table.

here begins the text immediately after 5*3 multiplication table. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis tellus. Donec ante dolor, iaculis nec, gravida ac, cursus in, eros. Mauris vestibulum, felis et egestas ullamcorper, purus nibh vehicula sem, eu egestas ante nisl non justo. Fusce tincidunt, lorem nec dapibus consectetuer, leo orci mollis ipsum, eget suscipit eros purus in ante. At ipsum vitae est lacinia tincidunt. Maecenas elit orci, gravida ut, molestie non, venenatis vel, lorem. Sed lacinia. Suspendisse potenti. Sed ultricies cursus lectus. In id magna sit amet nibh suscipit euismod. Integer enim. Donec sapien ante, accumsan ut, sodales commodo, auctor quis, lacus. Maecenas a elit lacinia urna posuere sodales. Curabitur pede pede, molestie id, blandit vitae, varius ac, purus. Mauris at ipsum vitae est lacinia tincidunt. Maecenas elit orci, gravida ut, molestie non, venenatis vel, lorem. Sed lacinia. Suspendisse potenti. Sed ultricies cursus lectus. In id magna sit amet nibh suscipit euismod. Integer enim. Donec sapien ante, accumsan ut, sodales commodo, auctor quis, lacus. Maecenas a elit lacinia urna posuere sodales. Curabitur pede pede, molestie id, blandit vitae, varius ac, purus.

However, do not put preformatted text there, it may overlap the table because it does not wrap. To prevent this, use  :

here begins the text immediately after 4*3 multiplication table. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis tellus. Donec ante dolor, iaculis nec, gravida ac, cursus in, eros. Mauris vestibulum, felis et egestas ullamcorper, purus nibh vehicula sem, eu egestas ante nisl non justo. Fusce tincidunt, lorem nec dapibus consectetuer, leo orci mollis ipsum, eget suscipit eros purus in ante. now comes the cleared BR:  here it was so preformatted text will start only after the table ended

You can use align=left, table will appear at the left and the following text to the right of it (but perhaps too close):

here begins the text immediately after 2*3 multiplication table. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis tellus. Donec ante dolor, iaculis nec, gravida ac, cursus in, eros. Mauris vestibulum, felis et egestas ullamcorper, purus nibh vehicula sem, eu egestas ante nisl non justo. Fusce tincidunt, lorem nec dapibus consectetuer, leo orci mollis ipsum, eget suscipit eros purus in ante. At ipsum vitae est lacinia tincidunt. Maecenas elit orci, gravida ut, molestie non, venenatis vel, lorem. Sed lacinia. Suspendisse potenti. Sed ultricies cursus lectus. In id magna sit amet nibh suscipit euismod. Integer enim. Donec sapien ante, accumsan ut, sodales commodo, auctor quis, lacus. Maecenas a elit lacinia urna posuere sodales. Curabitur pede pede, molestie id, blandit vitae, varius ac, purus. Mauris at ipsum vitae est lacinia tincidunt. Maecenas elit orci, gravida ut, molestie non, venenatis vel, lorem. Sed lacinia. Suspendisse potenti. Sed ultricies cursus lectus. In id magna sit amet nibh suscipit euismod. Integer enim. Donec sapien ante, accumsan ut, sodales commodo, auctor quis, lacus. Maecenas a elit lacinia urna posuere sodales. Curabitur pede pede, molestie id, blandit vitae, varius ac, purus.

Space around a table, image, or text
To create space around a table, image, or text, create a 1&times;1 table around it, with cellpadding:

Setting your column widths
If you wish to force column widths to your own requirements, rather than accepting the width of the widest text element in a column's cells, then follow this example. Note that wrap-around of text is forced.





Setting parameters
At the start of a cell, add your parameter followed by a single pipe. For example width=300px| will set that cell to a width of 300 pixels. To set more than one parameter, leave a space between each one.

Wikipedia code


What it looks like in your browser


Decimal point alignment
A method to get columns of numbers aligned at the decimal point is as follows:

gives

In simple cases one can dispense with the table feature and simply start the lines with a space, and put spaces to position the numbers:

432.1 43.21   4.321

Style templates
Some users have created templates to make table styles easier. Instead of remembering table parameters, you just include an appropriate style template after the. This helps keep table formatting consistent, and can allow a single change to the template to fix a problem or enhance the look of all tables that use it. For instance, this:

becomes this:

simply by replacing the  section with.

All of these templates should be organized/listed in a single place, like here.

Gallery
As a by-product of the image gallery feature, a table can be made with the gallery tag; if a text entry contains a link, the whole entry is ignored.