Open main menu

Changes

78,345 bytes added ,  16:55, 13 November 2012
no edit summary
{{dablink|For a basic introduction, see [[Help:Wikitable]]. For style considerations, see [[Wikipedia:Manual of Style/Tables]].}}
{{Shortcut|H:TABLE}}
{{Wiki markup}}

A '''wikitable''' is an arrangement of columns and rows used to organize and position data. Tables are useful for this purpose and there are many different styles and tricks that can be used to customise each. This page gives you information about syntax to build wikitables in Wikipedia.

== Using the toolbar ==
[[File:Advanced toolbar of vector skin.png|frame|center|Vector toolbar – default]]
[[File:Toolbar2.PNG|frame|center|Monobook toolbar]]

To automatically insert a table, click [[File:Vector toolbar insert table button.png]] or [[File:Button insert table.png]] (Insert a table) on the [[Help:Edit toolbar|edit toolbar]]. If "Insert a table" is not on the toolbar follow [[mw:Customizing edit toolbar|these directions]] to add it.

The following text is inserted when '''Insert a table''' is clicked:
<pre style="display: inline-block;">
{| class="wikitable"
|-
! Header text !! Header text !! Header text
|-
| Example || Example || Example
|-
| Example || Example || Example
|-
| Example || Example || Example
|}

</pre>
{| class="wikitable"
|-
! Header text !! Header text !! Header text
|-
| Example || Example || Example
|-
| Example || Example || Example
|-
| Example || Example || Example
|}
The sample text ("Header text" or "Example") is to be replaced with actual data.</div>

== Pipe syntax tutorial ==
{| border="3" style="margin-left: 3em;"
|-
! scope="col" | Column heading 1
! scope="col" | Column heading 2
! scope="col" | Column heading 3
|-
! scope="row" | Row heading 1
| Cell 2
| Cell 3
|-
! scope="row" | 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 ([[w:vertical bar|vertical bar]]) codes function exactly the same as [[w:HTML table|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 <code>'''{|'''</code> to begin a table, and <code>'''|}'''</code> to end it. Each one needs to be on its own line:
<span style="color: #a63;">'''<nowiki>{|</nowiki>'''</span>
''table code goes here''
<span style="color: #a63;">'''<nowiki>|}</nowiki>'''</span>
* An optional '''table caption''' is included with a line starting with a vertical bar and plus sign "<code>'''|+'''</code>" and the caption after it:
<nowiki>{|</nowiki>
<span style="color: #a63;">'''<nowiki>|+</nowiki> ''caption'''''</span>
''table code goes here''
<nowiki>|}</nowiki>
* To start a new '''table [[Row (database)|row]]''', type a vertical bar and a [[w:hyphen|hyphen]] on its own line: "<code>'''|-'''</code>". The codes for the cells in that row will start on the next line.
<nowiki>{|</nowiki>
<nowiki>|+</nowiki> The table's caption
<span style="color: #a63;">'''<nowiki>|-</nowiki>'''</span>
''row code goes here''
<span style="color: #a63;">'''<nowiki>|-</nowiki>'''</span>
''next row code goes here''
<nowiki>|}</nowiki>
* Type the codes for each ''table [[w:cell|cell]]'' in the next row, starting with a bar:
<nowiki>{|</nowiki>
<nowiki>|+</nowiki> The table's caption
<nowiki>|-</nowiki>
<span style="color: #a63;">'''|'''</span> ''cell code goes here''
<nowiki>|-</nowiki>
<span style="color: #a63;">'''|'''</span> ''next row cell code goes here''
<span style="color: #a63;">'''|'''</span> ''next cell code goes here''
<nowiki>|}</nowiki>
* Cells can be separated with either a new line and a single bar, a new line and a double bar, or by a double bar "<code>'''||'''</code>" on the same line. All three produce the same output:
<nowiki>{|</nowiki>
<nowiki>|+</nowiki> The table's caption
<nowiki>|-</nowiki>
<span style="color: #a63;">'''|Cell 1 || Cell 2 || Cell 3'''</span>
<nowiki>|-</nowiki>
<span style="color: #a63;">'''|Cell A'''</span>
<span style="color: #a63;">'''|Cell B'''</span>
<span style="color: #a63;">'''|Cell C'''</span>
<nowiki>|}</nowiki>
* Cell code that contains a single bar in the text will fail to render as expected: cell code between the first two single bars, or between a double bar and the first single bar becomes (optional) row formatting code. Leaving it blank has the effect of merging single bars into the text:
<nowiki>{| border="1"</nowiki>
<nowiki>|-</nowiki>
<nowiki>|format modifier (not displayed)</nowiki> <span style="color: #a63;">'''|'''</span><nowiki>These all </nowiki> <span style="color: #a63;">'''|'''</span><nowiki>(including the pipes)</nowiki> <span style="color: #a63;">'''|'''</span><nowiki>go into </nowiki> <span style="color: #a63;">'''|'''</span><nowiki>the first cell||second cell</nowiki>
<nowiki>|-</nowiki>
<nowiki>|format </nowiki> <span style="color: #a63;">'''|'''</span><nowiki>These all </nowiki> <span style="color: #a63;">'''||'''</span><nowiki>format</nowiki> <span style="color: #a63;">'''|'''</span><nowiki>go into </nowiki> <span style="color: #a63;">'''|'''</span><nowiki>the second cell</nowiki>
<nowiki>|}</nowiki>
which is probably not what you expected:
{| border="1"
|-
| format modifier (not displayed)|These all |(including the pipes)|go into |the first cell||second cell
|-
|format|These all||format|go into|the second cell
|}
However, the format modifier is useful:
<nowiki>{| border="1"</nowiki>
<nowiki>|-</nowiki>
<nowiki>| Cell 1 (no modifier&nbsp;— not aligned)</nowiki>
<nowiki>|-</nowiki>
<nowiki>| align="right" | Cell 2 (right aligned)</nowiki>
<nowiki>|}</nowiki>

{| border="1"
|-
| Cell 1 (no modifier&nbsp;— not aligned)
|-
| style="text-align: right;" | Cell 2 (right aligned)
|}

Just remember: no more than 2 single pipes on a line!
* a row of '''column headings''' is identified by using "<code>! scope="col" |</code>" instead of "<code>|</code>", and using "<code>!! scope="col" |</code>" instead of "<code>||</code>". Header cells typically render differently from regular cells, depending on the browser. They are often rendered in a bold font and centered. <code>scope="col"</code> is unnecessary in wikitables styled with class markup: <code>class="wikitable"</code> and so on.
<nowiki>{|</nowiki>
<nowiki>|+</nowiki> The table's caption
<span style="color: #a63;">'''! scope="col" | Column heading 1'''
'''! scope="col" | Column heading 2'''
'''! scope="col" | Column heading 3'''</span>
<nowiki>|-</nowiki>
| Cell 1 || Cell 2 || Cell 3
<nowiki>|-</nowiki>
| Cell A
| Cell B
| Cell C
<nowiki>|}</nowiki>
* the first cell of a row is identified as a '''row heading''' by starting the line with "<code>! scope="row" |</code>" instead of "<code>|</code>", and starting subsequent data cells on a new line. <code>scope="row"</code> is unnecessary in wikitables styled with class markup: <code>class="wikitable"</code> and so on.
<nowiki>{|</nowiki>
<nowiki>|+</nowiki> The table's caption
! scope="col" | Column heading 1
! scope="col" | Column heading 2
! scope="col" | Column heading 3
<nowiki>|-</nowiki>
<span style="color: #a63;">'''! scope="row" | Row heading 1'''</span>
| Cell 2 || Cell 3
<nowiki>|-</nowiki>
<span style="color: #a63;">'''! scope="row" | Row heading A'''</span>
| Cell B
| Cell C
<nowiki>|}</nowiki>
* Optional '''parameters''' can modify the behavior of cells, rows, or the entire table. For instance, a border could be added to the table:
<nowiki>{|</nowiki> <span style="color: #a63;">'''border="1"'''</span>
<nowiki>|+</nowiki> The table's caption
! scope="col" | Column heading 1
! scope="col" | Column heading 2
! scope="col" | Column heading 3
<nowiki>|-</nowiki>
! scope="row" | Row heading 1
| Cell 2 || Cell 3
<nowiki>|-</nowiki>
! scope="row" | Row heading A
| Cell B
| Cell C
<nowiki>|}</nowiki>
The final table would display like this:

{| border="1"
|+ The table's caption
! scope="col" | Column heading 1
! scope="col" | Column heading 2
! scope="col" | Column heading 3
|-
! scope="row" | Row heading 1
| Cell 2 || Cell 3
|-
! scope="row" | Row heading A
| Cell B
| Cell C
|}

If you want narrow one-pixel wide borders around all the cells use this in the top line of the table:

<code>{| border="1" style="border-collapse:collapse;"</code>

Here is the revised table:

{| border="1" style="border-collapse:collapse;"
|+ The table's caption
! scope="col" | Column heading 1
! scope="col" | Column heading 2
! scope="col" | Column heading 3
|-
! scope="row" | Row heading 1
| Cell 2 || Cell 3
|-
! scope="row" | Row heading A
| Cell B
| Cell C
|}

The simplest way is to use Wikipedia's external style sheet for tables: <code>class="wikitable"</code> and so on.

<pre>
{| border="1" class="wikitable"
|+ 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
|}
</pre>

It produces this:

{| border="1" class="wikitable"
|+ 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 [[w:HTML|HTML]], see http://www.w3.org/TR/html401/struct/tables.html#edef-TABLE and [[w:Table (HTML)|Table (HTML)]]. However, the <code>colgroup</code> and <code>col</code> elements are currently not [[Help:HTML in wikitext#Permitted HTML|supported in MediaWiki]]. <code>Thead</code>, <code>tbody</code> and <code>tfoot</code> are supported from Mediawiki version 1.18 on ( Current version on Wikipedia: {{CURRENTVERSION}} ).

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 [[meta: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. For empty cells, use the non-breaking space <code>&amp;nbsp;</code> as content to ensure that the cells are displayed. To show a visible pipe in a cell, use <code>&lt;nowiki>|&lt;/nowiki></code> or <code>&amp;#124;</code>.

With colspan and rowspan cells can span several columns or rows, see the [[Help:Table#Mélange|Mélange]] example below. However, this has the disadvantage that [[help:sorting|sorting]] does not work properly anymore.

== Examples ==
=== Simple example ===
Both of these generate the same output. Choose a style based on the number of cells in each row and the total text inside each cell.

The wiki markup code:
<pre>
{|
| A
| B
|-
| C
| D
|}
</pre>

<pre>
{|
| A || B
|-
| C || D
|}
</pre>

As it appears in a browser (note that there are no borders):
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">
{|
|-
| A
| B
|-
| C
| D
|}
</div>

=== Multiplication table ===
Here is the wiki markup code below. Note that <code>class="wikitable"</code> is used to style the table with Wikipedia's external style sheet for tables. It adds borders, background shading, and bold header text.

<pre style="overflow: auto;">
{| class="wikitable" style="text-align:center; width:200px; height:200px;"
|+ Multiplication table
|-
! ×
! 1
! 2
! 3
|-
! 1
| 1 || 2 || 3
|-
! 2
| 2 || 4 || 6
|-
! 3
| 3 || 6 || 9
|-
! 4
| 4 || 8 || 12
|-
! 5
| 5 || 10 || 15
|}
</pre>

As it appears in a browser:

{| class="wikitable" style="text-align:center; width:200px; height:200px;"
|+ Multiplication table
|-
! ×
! 1
! 2
! 3
|-
! 1
| 1 || 2 || 3
|-
! 2
| 2 || 4 || 6
|-
! 3
| 3 || 6 || 9
|-
! 4
| 4 || 8 || 12
|-
! 5
| 5 || 10 || 15
|}

=== Color; scope of parameters ===
Two ways of specifying [[Wikipedia:Colours|color]] of text and background for a single cell are as follows. The first form is preferred because the second form uses deprecated HTML:

The wiki markup code:
<pre style="display: inline-block;">
{|
| style="background: red; color: white" | abc
| def
| bgcolor="red" | <font color="white"> ghi </font>
| jkl
|}
</pre>

As it appears in a browser:
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">
{|
|-
| style="background: red; color: white" | abc
| def
| style="background: red;"| <span style="color: white;"> ghi </span>
| jkl
|}
</div>

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. (Note that there is no easy way to specify a color for a whole column—each cell in the column must be individually specified. Tools can make it easier.)

The wiki markup code:
<pre style="display: inline-block;">
{| style="background: yellow; color: green"
|-
| abc || def || ghi
|- style="background: red; color: white"
| jkl || mno || pqr
|-
| stu || style="background: silver" | vwx || yz
|}
</pre>

As it appears in a browser:
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">
{| style="background: yellow; color: green"
|-
| abc || def || ghi
|- style="background: red; color: white"
| jkl || mno || pqr
|-
| stu || style="background: silver" | vwx || yz
|}
</div>

To make the table blend in with the background, use <code>style="background: none;"</code> or <code>style="background: transparent;"</code>. (Warning: <code>style="background: inherit;"</code>, does not work with some browsers, including IE6!)

To force a cell to match one of the default colors of the [[Help:User style|<code>class="wikitable"</code> template]], use <code>style="background: #f2f2f2"</code> for the darker header, and <code>style="background: #f9f9f9"</code> for the lighter body.

See: [[w:Style|style]], [[w:Background|background]], [[w:List of colors|list of colors]], [[w:Web colors|web colors]] and the template [[Template:Coltit/doc|Coltit]].

=== 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.

The wiki markup code:
<pre style="display: inline-block;">
{| style="width: 75%; height: 200px" border="1"
|-
| abc || def || ghi
|- style="height: 100px;"
| jkl || style="width: 200px;" | mno || pqr
|-
| stu || vwx || yz
|}
</pre>

As it appears in a browser:
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">
{| style="width:75%; height:200px" border="1"
|-
| abc || def || ghi
|- style="height: 100px;"
| jkl || style="width: 200px;" | mno || pqr
|-
| stu || vwx || yz
|}
</div>

Note that <code>style="</code>inline CSS<code>"</code> has no effect with some browsers. If compatibility is important, equivalent older constructs like <code>width="75%"</code> should work on more browsers.

==== Setting column widths ====
To force column widths to specific requirements, rather than accepting the width of the widest text element in a column's cells, follow this example. Note that [[word wrap|wrap-around of text]] is forced.

The wiki markup code:
<pre style="display: inline-block;">
{| border="1" cellpadding="2"
! scope="col" width="50px" | Name
! scope="col" width="225px" | Effect
! scope="col" width="225px" | Games found in
|-
| Poké Ball || Regular Poké Ball || All versions
|-
| Great Ball || Better than a Poké Ball || All versions
|}
</pre>

<div style="background: white; border: 1px solid black; padding: 1em;">
{| border="1" cellpadding="2"
|-
! scope="col" width="50" | Name
! scope="col" style="width: 225px;" | Effect
! scope="col" style="width: 225px;" | Games found in
|-
|Poké Ball || Regular Poké Ball || All versions
|-
|Great Ball || Better than a Poké Ball || All versions
|}
</div>

To set column widths in a table without headers, specify the width in the first cell for each column, like this:

<pre style="display: inline-block;">
{| border="1" cellpadding="2"
|-
| width="100pt" | This column is 100 points wide
| width="200pt" | This column is 200 points wide
| width="300pt" | This column is 300 points wide
|-
| blah || blih || bluh
|}
</pre>

<div style="background: white; border: 1px solid black; padding: 1em;">
{| border="1" cellpadding="2"
|-
| style="width: 100pt;" | This column is 100 points wide
| style="width: 200pt;" | This column is 200 points wide
| style="width: 300pt;" | This column is 300 points wide
|-
| blah || blih || bluh
|}
</div>

One application of setting the widths is aligning columns of consecutive tables:

{| border="1" cellpadding="2"
|-
! scope="col" style="width: 350px;" | Country
! scope="col" style="width: 225px;" | Capital
|-
| The Netherlands || Amsterdam
|}

{| border="1" cellpadding="2"
|-
! scope="col" style="width: 350px;" | Country
! scope="col" style="width: 225px;" | Capital
|-
| France || Paris
|}

===== Nowrap =====
In a table that spans the entire width of a page, cells narrower than the widest cell tend to wrap. To keep an entire column from wrapping, use <code>style=white-space:nowrap</code> in a non-header cell on the longest/widest cell to affect the entire column.

Before:
{|"class=wikitable sortable" border="1"
|-
! scope="col" | Episode
! scope="col" | Date
! scope="col" | Summary
|-
|"The Journey Begins"
|January 1, 2010
|[[Lorem ipsum]] dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|-
|"When Episodes Attack"
|January 8, 2010
|Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|-
|"So Long"
|January 15, 2010
|Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|}

After:
{|"class=wikitable sortable" border="1"
|-
! scope="col" | Episode
! scope="col" | Date
! scope="col" | Summary
|-
|"The Journey Begins"
|January 1, 2010
|Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|-
|style=white-space:nowrap|"When Episodes Attack"
|January 8, 2010
|Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|-
|"So Long"
|style=white-space:nowrap|January 15, 2010
|Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|}

=== Setting borders ===
Table borders default to a complex shaded double-line (the default in HTML); however, those borders can be set to a thin solid line by using a style-parameter (style="border: 1px solid darkgray"), as in the following (''Note: if you intend to use the 'cellpadding' or 'cellspacing' options along with a border, you MUST use this format''):

<pre style="display: inline-block;">
{| cellpadding="2" style="border: 1px solid darkgray;"
! width="140" | Left
! width="150" | Middle
! width="130" | Right
|- border="0"
| [[File:StarIconBronze.png|120px]]
| [[File:StarIconGold.png|120px|Caption when mouse-over image]]
| [[File:StarIconGreen.png|120px|Green stellar icon]]
|- align="center"
| Bronze star || Gold star || Green star
|}
</pre>
Note the bottom-row texts are centered by 'align="center"' while star-images were not centered.

{| cellpadding="2" style="border: 1px solid darkgrey; margin-left: 4em;"
|-
! style="width: 140px;" | Left
! style="width: 150px;" | Middle
! style="width: 130px;" | Right
|- border="0"
| [[File:StarIconBronze.png|120px]]
| [[File:StarIconGold.png|120px|Caption when mouse-over image]]
| [[File:StarIconGreen.png|120px|Green stellar icon]]
|- align="center"
| Bronze star || Gold star || Green star
|}

As long as the "Image:" specs omit the parameter "thumb|" they will not show the caption lines in the table (only during mouse-over). The border color "darkgray" matches typical tables or infoboxes in articles; however, it could be any color name (such as style="border: 1px solid darkgreen;") or use a hex-color (such as: #DDCCBB).

A column format-specifier (enclosed in "|...|") can have a style-parameter to set borders on each cell, as follows:

<pre style="display: inline-block;">
{| cellpadding="2" style="border: 1px solid darkgray;"
! width="140" | Left
! width="150" | Middle
! width="130" | Right
|- align="center"
| style="border: 1px solid blue;"|
[[File:StarIconBronze.png|120px]]
| style="border: 1px solid #777777;"|
[[File:StarIconGold.png|120px|Caption when mouse-over image]]
| style="border: 1px solid #22AA55;"|<!--greenish border-->
[[File:StarIconGreen.png|120px|Green stellar icon]]
|- align="center"
|Bronze star || Gold star || Green star
|}
</pre>

Note only the image cells, here, have individual borders, not the text.
{| cellpadding="2" style="border: 1px solid darkgrey; margin-left:4em;"
|-
! style="width:140px;"|Left || style="width:150px;"|Middle || style="width:130px;"|Right
|- align="center"
| style="border: 1px solid blue;"|
[[File:StarIconBronze.png|120px]]
| style="border: 1px solid #777;"|
[[File:StarIconGold.png|120px|Caption when mouse-over image]]
| style="border: 1px solid #2a5;"|<!--greenish border-->
[[File:StarIconGreen.png|120px|Green stellar icon]]
|- align="center"
|Bronze star || Gold star || Green star
|}
The lower hex-colors (such as: #616161) are closer to black. Typically, all borders in a table would be one specific color.

=== Vertical alignment ===
By default data in tables is vertically centrally aligned, which results in odd-looking layouts like this:

{| border="1" cellpadding="2" style="width:400px; margin-left:6em;"
|-
! scope="row" style="width:10%;"| Row heading
| style="width:70%;"|A longer piece of text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
| style="width:20%;"|short text
|-
! scope="row" | Row heading
| Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br /><span style="color: #13a;">Imagine someone scrolling down the page, seeing the tops of "empty" columns, and wondering why they're empty. Use "'''valign=top'''" to align text at the top of columns.</span>
| short text
|}

To fix this, apply the valign="top" attribute to the rows (unfortunately it seems to be necessary to apply this individually to every single row). For example:
<pre style="display: inline-block;">
{| border="1" cellpadding="2" width="400"
|- valign="top"
! scope="row" width="10%" | Row heading
| width="70%" | A longer piece of text. Lorem ipsum...
| width="20%" | short text
|- valign="top"
! scope="row" | Row heading
| Excepteur sint occaecat...
| short text
|}
</pre>

{| border="1" cellpadding="2" style="width: 400px; margin-left: 6em;"
|- valign="top"
! scope="row" style="width: 10%;" | Row heading
| style="width: 70%;" | A longer piece of text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
| style="width: 20%;" | short text
|- valign="top"
! scope="row" | Row heading
| Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br /><span style="color: #14a;">Imagine someone scrolling down the page, seeing the tops of "empty" columns, and wondering why they're empty. Use "'''valign=top'''" to align text at the top of columns.</span>
| short text
|}

=== Cell content indenting ===
The contents of a cell can be indented using a CSS style of <code>padding-left</code>. For example:
<pre style="display: inline-block;">
{| border="1" cellpadding="2"
|-
| Cell content that is not indented || 1
|-
| style="padding-left: 2em" | Indented content || 2
|}
</pre>

{| border="1" cellpadding="2"
|-
| Cell content that is not indented || 1
|-
| style="padding-left: 2em" | Indented content || 2
|}

=== Positioning ===
You can position the table itself, the contents of a row, and the contents of a cell, but not with a single parameter for all the contents of the table. See [[m:Template talk:Table demo]].

Prior to April 2009, using "float" to position a table was discouraged; however, it no longer always breaks page rendering at large font sizes. See a floated image, below, under "[[#Floating images in the center|Floating images in the center]]".

=== Mélange ===
''Note: This example is not [[MOS:ACCESS|accessible]], and should be avoided as much as possible. For example, nested tables (tables inside tables) should be separated into distinct tables when possible.''

Here is a more advanced example, showing some more options available for making up tables. Note however that with colspan and rowspan [[help:sorting|sorting]] does not work properly anymore.

Users can play with these settings in their own table to see what effect they have. Not all of these techniques may be appropriate in all cases; just because colored backgrounds can be added, for example, does not mean it is always a good idea. Try to keep the markup in tables relatively simple—remember, other people are going to be editing the article too! This example should give an idea of what is possible, though.

The wiki markup code:
<pre style="display: inline-block;">
{| border="1" cellpadding="5" cellspacing="0" align="center"
|+ '''An example table'''
|-
! style="background: #efefef;" | First header
! colspan="2" style="background: #ffdead;" | Second header
|-
| upper left
| &amp;nbsp;
| rowspan="2" style="border-bottom: 3px solid grey;" valign="top" |
right side
|-
| style="border-bottom: 3px solid grey;" | lower left
| style="border-bottom: 3px solid grey;" | lower middle
|-
| colspan="3" align="center" |
{| border="0"
|+ ''A table in a table''
|-
| align="center" width="150" | [[File:Wiki.png]]
| align="center" width="150" | [[File:Wiki.png]]
|-
| align="center" colspan="2" style="border-top: 1px solid red;<!--
--> border-right: 1px solid red; border-bottom: 2px solid red;<!--
--> border-left: 1px solid red;" |
Two Wikipedia logos
|}
|}
</pre>

As it appears in a browser:
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">
{| border="1" cellpadding="1" cellspacing="0" style="margin: auto;"
|+ '''An example table'''
|-
! style="background: #efefef;" | First header
! colspan="2" style="background: #ffdead;" | Second header
|-
| upper left
| &nbsp;
| rowspan="2" style="border-bottom: 3px solid gray; vertical-align: top;"|
right side
|-
| style="border-bottom: 3px solid gray;" | lower left
| style="border-bottom: 3px solid gray;" | lower middle
|-
| colspan="3" style="text-align: center;" |
{| border="0"
|+ ''A table in a table''
|- style="text-align: center;"
|| [[File:Wiki.png]]
| style="width: 150px;" | [[File:Wiki.png]]
|-
| colspan="2" style="text-align: center; border-top: 1px solid red; <!--
--> border-right: 1px solid red; border-bottom: 2px solid red; <!--
--> border-left: 1px solid red;"|
Two Wikipedia logos
|}
|}
</div>

=== Floating table ===
The wiki markup coding:
<pre style="display: inline-block;">
This paragraph is before the table. Lorem ipsum dolor sit
amet, consectetur adipisicing elit, sed do eiusmod...

{| style="float: right;" border="1"
| Col 1, row 1
| rowspan="2" | Col 2, row 1 (and 2)
| Col 3, row 1
|-
| Col 1, row 2
| Col 3, row 2
|}

Note the floating-table to the right.

This paragraph is after the table. The text in column 2
will span both rows due to format specifier "rowspan=2" so there
is no coding for "Col 2" in the 2nd row, just: Col 1 & Col 3.
</pre>

As it appears in a browser:
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

This paragraph is before the table. Lorem ipsum dolor sit
amet, consectetur adipisicing elit, sed do eiusmod...
{| style="float: right;" border="1"
|-
| Col 1, row 1
| rowspan="2" | Col 2, row 1 (and 2)
| Col 3, row 1
|-
| Col 1, row 2
| Col 3, row 2
|}
Note the floating-table to the right.

This paragraph is after the table. The text in column 2
will span both rows due to format specifier "rowspan=2" so there
is no coding for "Col 2" in the 2nd row, just: Col 1 & Col 3.
</div>

=== Floating images in the center ===
A table can be used to wrap an image, so that the table can float towards the center of the page (such as using: style="float: right;"). However, the table margins, border and font-size must be precisely set to match a typical image display. The Image-spec parameter "thumb|" (although auto-thumbnailing to user-preference width) forces a wide left-margin that squeezes the nearby text, so the parameter "center|" can be added to suppress the left-margin padding. However, "center" sometimes shoves the caption to a 2nd line (under a centered box "[]"), so "thumb|" could be omitted and just hard-code the image size, adding a gray (#BBB) border. Using precise parameters to match other images, a floating-image table can be coded as follows:
<pre style="display: inline-block;">
{| style="float: right; border: 1px solid #BBB; margin: .46em 0 0 .2em;"
|- style="font-size: 86%;"
| valign="top" |[[File:DuraEuropos-TempleOfBel.jpg|180px]]<!--
--><br /> Temple of [[Bel (mythology)|Bel]] (floating).
|}
</pre>

The text inside the floating-table is sized by style="font-size: 86%;". That floating-image table floats a typical image-box, but allows adjusting the left-hand margin of the image (see temple-example floating below).
{| class="infobox" style="width: 90px;"
|-
! colspan="2" | Infobox A
|-
| colspan="2" | This sample infobox shows how the floating image-box aligns toward the center.
|}
{| style="float: right; border: 1px solid #BBB; margin: .46em 0 0 .2em;"
|- style="font-size: 86%;"
| valign="top" |[[File:DuraEuropos-TempleOfBel.jpg|180px]]<br /><!--
-->&nbsp;Temple of [[Bel (mythology)|Bel]]&nbsp;(floating).
|}
{| style="float: right; clear:right; border: 1px solid black;"
| valign="top" |[[File:DuraEuropos-TempleOfBel.jpg|thumb<!--
-->|right|This table shows the implicit margins of <!--
--> Images using "right".]]
|}
The caption-text can be omitted, or remove the parameter "thumb|" so the caption is hidden until "mouse-over display". Unfortunately the parameter "thumb|" (used for displaying the caption) also controls the auto-thumbnailing to re-size images by user-preferences size. In April 2009, it was not possible to have auto-thumbnail sizing while also concealing the caption: parameter "thumb|" triggers both actions and forces the caption to display.

An image set with parameter "left|" will gain a wide right-side margin (opposite margin of parameter "right|"), so floating toward the left would require an image set as "center|" inside a table with style="float:left; margin:0.46em 0.2em".

Recall that, outside an image-table, the parameter "right|" causes an image to align (either) above or below an infobox, but would not float alongside the infobox.

Note the ''order of precedence'': first come infoboxes or images using "right|", then come the floating-tables, and lastly, any text will wrap that can still fit. If the first text-word is too long, no text will fit to complete the left-hand side, so beware creating a "ragged left margin" when not enough space remains for text to fit alongside floating-tables.

If multiple single image-tables are stacked, they will float to align across the page, depending on page-width. The text will be squeezed to allow as many floating-tables as can fit, as auto-aligned, then wrap whatever text (can still fit) at the left-hand side.
{| style="float: right; margin-left:0.2em; border: 1px solid #BBB;"
|- style="font-size: 87%;"
| valign="top" |[[File:DuraEuropos-TempleOfBel.jpg<!--
-->|105px]]<br />...by float: right
|}
{| style="float: right; margin-left:0.2em; border: 1px solid #BBB;"
|- style="font-size: 87%;"
| valign="top" |[[File:DuraEuropos-TempleOfBel.jpg<!--
-->|105px]]<br /> ...images wrap...
|}
{| style="float: right; margin-left:0.2em; border: 1px solid #BBB;"
|- style="font-size: 87%;"
| valign="top" |[[File:DuraEuropos-TempleOfBel.jpg<!--
-->|105px]]<br />All these...
|}

That auto-aligning feature can be used to create a "floating-gallery" of images: a set of 20 floating-tables will wrap (backward, right-to-left) as if each table were a word of text to wrap across and down the page. To wrap in the typical direction (wrapping left-to-right) define all those floating-tables, instead, as left-side tables using the top parameter style="float:left; margin:0.46em 0.2em". Multiple floating-images empower more flexible typesetting of images around the text.

=== Nested tables ===
''Note: because they cause [[Wikipedia:Manual of Style (accessibility)#Tables|accessibility issues]], nested tables should be avoided whenever possible.''

Seven different (blue) tables are shown nested inside the cells of a table. Automatically the two tables |A| and |B|B| are vertically aligned instead of the usual side by side of text characters in a cell. "float" is used to fix each of tables |C| and |D| to their own position within one cell of the table. This may be used for charts and schemes. ''Nested tables must start on a new line.''

'''Wiki markup'''
<!-- <div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">-->
<p style="border: 1px dashed #2f6fab; background: #f9f9f9; padding: 1em"><code>
<nowiki>{|</nowiki> border="1"<br />
| &amp;alpha;<br />
| style="text-align: center;"| cell2<br />
<span style="color: navy;">
'''<nowiki>{|</nowiki> border="2" style="background: #ABCDEF;"''' <nowiki><!--</nowiki> '''The nested table must be on a new line''' <nowiki>--></nowiki><br />
'''| NESTED'''<br />
'''|-'''<br />
'''| TABLE'''<br />
'''<nowiki>|}</nowiki>'''<br />
</span>
| style="vertical-align:bottom;"| the original table again<br />
| style="width:100px;" |<br />
<span style="color: navy;">
'''<nowiki>{|</nowiki> border="2" style="background: #ABCDEF;"'''<br />
'''| A'''<br />
'''<nowiki>|}</nowiki>'''<br />
'''<nowiki>{|</nowiki> border="2" style="background: #ABCDEF;"'''<br />
'''| B || B'''<br />
'''<nowiki>|}</nowiki>'''<br />
</span>
| style="width:50px;" |<br />
<span style="color: navy;">
'''<nowiki>{|</nowiki> border="2" style="background: #ABCDEF; float:left;"'''<br />
'''| C'''<br />
'''<nowiki>|}</nowiki>'''<br />
'''<nowiki>{|</nowiki> border="2" style="background: #ABCDEF; float: right;"'''<br />
'''| D'''<br />
'''<nowiki>|}</nowiki>'''<br />
</span>
<nowiki>|}</nowiki>
</code></p><!--</div>-->

'''As it appears in a browser''':
{| border="1"
|-
| α
| style="text-align: center;"| cell2
{| border="2" style="background: #ABCDEF;"
|-
| NESTED
|-
| TABLE
|}
| style="vertical-align: bottom;" | the original table again
| style="width: 100px;" |
{| border="2" style="background: #ABCDEF;"
|-
| A
|}
{| border="2" style="background: #ABCDEF;"
|-
| B || B
|}
| style="width: 50px;" |
{| border="2" style="background: #ABCDEF; float:left;"
|-
| C
|}
{| border="2" style="background: #ABCDEF; float: right;"
|-
| D
|}
|}

=== Combined use of COLSPAN and ROWSPAN ===
'''Wiki markup'''
<pre style="display: inline-block;">
{| border="1" cellpadding="5" cellspacing="0"
|-
| Column 1 || Column 2 || Column 3
|-
| rowspan="2" | A
| colspan="2" style="text-align: center;" | B
|-
| C <!-- column 1 occupied by cell A -->
| D
|-
| E
| rowspan="2" colspan="2" style="text-align: center;" |F
|-
| G <!-- column 2+3 occupied by cell F -->
|-
| colspan="3" style="text-align: center;" | H
|}
</pre>

'''As it appears in a browser''':
{| border="1" cellpadding="5" cellspacing="0"
|-
| Column 1 || Column 2 || Column 3
|-
| rowspan="2" | A
| colspan="2" style="text-align: center;" | B
|-
| C <!-- column 1 occupied by cell A -->
| D
|-
| E
| rowspan="2" colspan="2" style="text-align: center;" | F
|-
| G <!-- column 2+3 occupied by cell F -->
|-
| colspan="3" style="text-align: center;" | H
|}

Note that using <code>rowspan="2"</code> for cell '''G''' combined with <code>rowspan="3"</code> for cell '''F''' to get another row below '''G''' and '''F''' won't work, because all (implicit) cells would be empty.
Likewise complete columns are not displayed if all their cells are empty. Borders between non-empty and empty cells might be also not displayed (depending on the browser), use <code>&amp;nbsp;</code> to fill an empty cell with dummy content.

=== Centering tables ===
Centered tables can be achieved, but they will not "float"; that is to say, no text will appear to either side. The trick is <code><nowiki>{| style="margin: 1em auto 1em auto;"</nowiki></code>

'''Wiki markup'''
<pre style="display: inline-block;">
{| class="wikitable" style="margin: 1em auto 1em auto;"
|+ '''Cells left-aligned, table centered'''
! scope="col" | Duis
! scope="col" | aute
! scope="col" | irure
|-
| dolor || in reprehenderit || in voluptate velit
|-
| esse cillum dolore || eu fugiat nulla || pariatur.
|}
</pre>

'''As it appears in a browser''':
{| class="wikitable" style="margin: 1em auto 1em auto;"
|+ '''Cells left-aligned, table centered'''
! Duis || aute || irure
|-
| dolor || in reprehenderit || in voluptate velit
|-
| esse cillum dolore || eu fugiat nulla || pariatur.
|}

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

<pre style="display: inline-block;">
{| style="color:white"
|-
| bgcolor="red"|cell1 || width="300" bgcolor="blue"|cell2
| bgcolor="green"|cell3
|}
</pre>

As it appears in a browser:
{| style="color:white"
|-
| style="background:red;"|cell1 || style="width:300px; background:blue;"|cell2 || style="background:green;"|cell3
|}

=== Decimal point alignment ===
A method to get columns of numbers aligned at the decimal point is as follows:
<pre style="display: inline-block;">
{| cellpadding="0" cellspacing="0"
| align="right" | 432 || .1
|-
| align="right" | 43 || .21
|-
| align="right" | 4 || .321
|}
</pre>

As it appears in a browser:
<div style="background:white; border: 1px solid darkgrey;">
{| cellpadding="0" cellspacing="0"
|-
| align="right" | 432 || .1
|-
| align="right" | 43 || .21
|-
| align="right" | 4 || .321
|}
</div>

If the column of numbers appears in a table with cell padding or cell spacing, you can still align the decimal points without an unsightly gap in the middle. Embed a table in each number's cell and specify its column widths. Make the embedded tables' column widths the same for each cell in the column. (If decimal points are still misaligned using this method, the main table's column may be too narrow. Add a parameter to increase the column's width.)
The wiki markup code:
<pre style="display: inline-block;">
{| border="1" cellpadding="4" cellspacing="2"
|
{| cellpadding="0" cellspacing="0" width="100"
| align="right" width="50%"| 432 || width="50%" | .1
|}
|-
|
{| cellpadding="0" cellspacing="0" width="100"
| align="right" width="50%"| 43 || width="50%" | .21
|}
|-
|
{| cellpadding="0" cellspacing="0" width="100"
| align="right" width="50%" | 4 || width="50%" | .321
|}
|}
</pre>

As it appears in a browser:
<div style="background:white; border: 1px solid darkgrey;">
{| border="1" cellpadding="4" cellspacing="2"
|
{| cellpadding="0" cellspacing="0" style="width: 100px;"
|-
| style="text-align: right; width: 50%;" | 432 || style="width: 50%;" | .1
|}
|-
|
{| cellpadding="0" cellspacing="0" style="width:100px;"
|-
| style="text-align: right; width: 50%;" | 43 || style="width: 50%;" | .21
|}
|-
|
{| cellpadding="0" cellspacing="0" style="width:100px;"
|-
| style="text-align: right; width: 50%;" | 4 || style="width: 50%;" | .321
|}
|}
</div>

In the case of preformatted text, you can dispense with the table feature entirely and simply start the lines with a space, and put spaces to position the numbers:

432.1
43.21
4.321

However, there should be a good reason to use pre-formatted text in an article.

== Classes ==
{{See Also|Help:User style|Help:CSS}}

In the first line of table code, after the "{|", instead of specifying a style directly, you can also specify a class, which may be used to apply [[w:Cascading Style Sheets|styles]]. The style for this class can be specified in various ways:
* in the software itself, per skin (for example the class [[#Sorting|sortable]])
* collectively for all users of one wiki in [[MediaWiki:Common.css]] (for example, on this and some other projects there is or was the class wikitable, later moved to [http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/skins/common/shared.css?view=markup shared.css])
* separately per skin in [[MediaWiki:Monobook.css]] etc.
* individually on one wiki in a user subpage
* individually, but jointly for tables of the class concerned on all web pages, on the local computer of the user.

Instead of remembering table parameters, you just include an appropriate class after the <code>{|</code>. This helps keep table formatting consistent, and can allow a single change to the class to fix a problem or enhance the look of all the tables that are using it at once. For instance, this:

{| border="0" style="margin: auto;"
|-
| style="width:46%;" |
<div style="background:white; border:0 solid rgb(153, 153, 153); padding:1em;"><pre><nowiki>
{| cellpadding="2"
|+ Multiplication table
|-
! scope="col" | &amp;times;
! scope="col" | 1
! scope="col" | 2
! scope="col" | 3
|-
! scope="row" | 1
| 1 || 2 || 3
|-
! scope="row" | 2
| 2 || 4 || 6
|-
! scope="row" | 3
| 3 || 6 || 9
|-
! scope="row" | 4
| 4 || 8 || 12
|-
! scope="row" | 5
| 5 || 10 || 15
|}
</nowiki></pre></div>
|| || style="width:48%;" |
<div style="background:white; border:0 solid rgb(153, 153, 153); padding:1em;">
{| cellpadding="2"
|+ Multiplication table
|-
! scope="col" | ×
! scope="col" | 1
! scope="col" | 2
! scope="col" | 3
|-
! scope="row" | 1
| 1 || 2 || 3
|-
! scope="row" | 2
| 2 || 4 || 6
|-
! scope="row" | 3
| 3 || 6 || 9
|-
! scope="row" | 4
| 4 || 8 || 12
|-
! scope="row" | 5
| 5 || 10 || 15
|}
</div>
|-
| colspan="3" style="text-align: center;" | becomes this:
|-
| style="width:46%;" |
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki>
{| class="wikitable"
|+ Multiplication table
|-
! scope="col" | &amp;times;
! scope="col" | 1
! scope="col" | 2
! scope="col" | 3
|-
! scope="row" | 1
| 1 || 2 || 3
|-
! scope="row" | 2
| 2 || 4 || 6
|-
! scope="row" | 3
| 3 || 6 || 9
|-
! scope="row" | 4
| 4 || 8 || 12
|-
! scope="row" | 5
| 5 || 10 || 15
|}
</nowiki></pre></div>
|| || style="width:48%;" |
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">
{| class="wikitable"
|+ Multiplication table
|-
! scope="col" | ×
! scope="col" | 1
! scope="col" | 2
! scope="col" | 3
|-
! scope="row" | 1
| 1 || 2 || 3
|-
! scope="row" | 2
| 2 || 4 || 6
|-
! scope="row" | 3
| 3 || 6 || 9
|-
! scope="row" | 4
| 4 || 8 || 12
|-
! scope="row" | 5
| 5 || 10 || 15
|}
</div>
|}

simply by replacing inline CSS for the table by <code>class="wikitable"</code>. This is because the ''wikitable'' class in [[MediaWiki:Common.css]] contains a number of ''table.wikitable'' [[w:CSS|CSS]] style rules. These are all applied at once when you mark a table with the class. You can then add additional style rules if desired. These override the class's rules, allowing you to use the class style as a base and build up on it:

'''Wiki markup'''
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki>
{| class="wikitable" style="font-style:italic; font-size:120%; border: 3px dashed red;"
|+ Multiplication table
|-
! scope="col" | &amp;times;
! scope="col" | 1
! scope="col" | 2
! scope="col" | 3
|-
! scope="row" | 1
| 1 || 2 || 3
|-
! scope="row" | 2
| 2 || 4 || 6
|-
! scope="row" | 3
| 3 || 6 || 9
|-
! scope="row" | 4
| 4 || 8 || 12
|-
! scope="row" | 5
| 5 || 10 || 15
|}
</nowiki></pre></div>

'''As it appears in a browser''':
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">
{| class="wikitable" style="font-style:italic; font-size:120%; border: 3px dashed red;"
|+ Multiplication table
|-
! scope="col" | ×
! scope="col" | 1
! scope="col" | 2
! scope="col" | 3
|-
! scope="row" | 1
| 1 || 2 || 3
|-
! scope="row" | 2
| 2 || 4 || 6
|-
! scope="row" | 3
| 3 || 6 || 9
|-
! scope="row" | 4
| 4 || 8 || 12
|-
! scope="row" | 5
| 5 || 10 || 15
|}
</div>

Notice that the table retains the gray background of the wikitable class, and the headers are still bold and centered. But now the text formatting has been overridden by the local ''style'' statement; all of the text in the table has been made italic and 120% normal size, and the wikitable border has been replaced by the red dashed border.

Of course this works only for browsers supporting inline CSS, if it's important use XHTML markup like <code>&lt;big&gt;</code> instead of "font-size:120%", or Wiki markup like <code><nowiki>''text''</nowiki></code> instead of "font-style:italic".

=== Collapsible tables ===
Classes can also be used to collapse tables, so they are hidden by default. Use the style 'collapsible' to enable collapsing behaviour. By default, a collapsible table will begin expanded. To change this, include the additional class 'collapsed' or 'autocollapse' (i.e. only collapse if 3 other collapsible tables are present). You must include a header row, where the 'hide' option will be displayed. Example:

<pre style="display: inline-block;">
{| class="wikitable collapsible collapsed"
|-
! Header
|-
| Content which starts hidden
|-
| more hidden content
|}
</pre>

Gives:

{| class="wikitable collapsible collapsed"
|-
! Header
|-
| Content which starts hidden
|-
| more hidden content
|}

==== Using class mw-collapsible ====
Another way (worked in mediawiki 1.19rc1)[[testwiki:User:Krinkle/CollapsingTestpageMw]]
<pre style="display: inline-block;">{| class="wikitable sortable mw-collapsible"</pre>

{| class="wikitable sortable mw-collapsible"
|-
! Header
|-
| Content which starts visible
|-
| more visible content
|}

<pre style="display: inline-block;">{| class="wikitable sortable mw-collapsible mw-collapsed"</pre>
{| class="wikitable sortable mw-collapsible mw-collapsed"
|-
! Header
|-
| Content which starts hidden
|-
| more hidden content
|}

== Sorting ==
{{see also|Help:Sorting|meta:Help:Sorting}}

Tables can be made sortable by adding <code>class="sortable"</code>; for details see '''[[Help:Sorting]]'''. Since this can be very useful, it is wise to keep the possibilities and limitations of this feature in mind when designing a table. For example:
* Do not divide a table into sections by subheaders spanning several rows. Instead, an extra column can be made showing the content of these headers on each row, in a short form.
* Do not have elements spanning several columns; instead, again, repeat the content on each row, in a short form.
* In a column of numbers, do not put text such as "ca." before or after a number – it will break numerical sorting. Do not put any text or alphabetical characters in any cell of a column to be sorted numerically. Try not to put a range of numbers (it does not affect the sorting position for numeric sorting mode, and in the case of a range, the first number determines the position, but if, possibly after sorting this or another column, the element is at the top, it will induce alphabetic sorting mode). Instead, put these texts in a separate column. Alternatively, for the greatest flexibility, alphabetic sorting mode with hidden sortkeys can be used.

A long form of abbreviated content can be put as legend outside the table.

'''Wiki markup'''
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki>
{| class="wikitable sortable" border="1"
|+ Sortable table
|-
! scope="col" | Alphabetic
! scope="col" | Numeric
! scope="col" | Date
! scope="col" class="unsortable" | Unsortable
|-
| d || 20 || 2008-11-24 || This
|-
| b || 8 || 2004-03-01 || column
|-
| a || 6 || 1979-07-23 || cannot
|-
| c || 4 || 1492-12-08 || be
|-
| e || 0 || 1601-08-13 || sorted.
|}
</nowiki></pre></div>

'''As it appears in a browser''':
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">
{| class="wikitable sortable"
|+ Sortable table
|-
! scope="col" | Alphabetic
! scope="col" | Numeric
! scope="col" | Date
! scope="col" class="unsortable" | Unsortable
|-
| d || 20 || 2008-11-24 || This
|-
| b || 8 || 2004-03-01 || column
|-
| a || 6 || 1979-07-23 || cannot
|-
| c || 4 || 1492-12-08 || be
|-
| e || 0 || 1601-08-13 || sorted.
|}
</div>

=== Numerical and year sorting problems ===
See [[Help:Sorting]].

=== Sorting and collapsing ===
It is possible to collapse a sortable table. To do so, you need to use the code
<code>{| class="wikitable sortable collapsible"</code>. Taking the above table and making it collapsable gives you this:

'''Wiki markup'''
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki>
{| class="wikitable sortable collapsible" border="1"
|+ Sortable and collapsible table
|-
! scope="col" | Alphabetic
! scope="col" | Numeric
! scope="col" | Date
! scope="col" class="unsortable" | Unsortable
|-
| d || 20 || 2008-11-24 || This
|-
| b || 8 || 2004-03-01 || column
|-
| a || 6 || 1979-07-23 || cannot
|-
| c || 4.2 || 1492-12-08 || be
|-
| e || 0 || 1601-08-13 || sorted.
|}
</nowiki></pre></div>

'''As it appears in a browser''':
<div style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">
{| class="wikitable sortable collapsible"
|+ Sortable and collapsible table
|-
! scope="col" | Alphabetic
! scope="col" | Numeric
! scope="col" | Date
! scope="col" class="unsortable" | Unsortable
|-
| d || 20 || 2008-11-24 || This
|-
| b || 8 || 2004-03-01 || column
|-
| a || 6 || 1979-07-23 || cannot
|-
| c || 4.2 || 1492-12-08 || be
|-
| e || 0 || 1601-08-13 || sorted.
|}
</div>

If you want the table to default to collapsed state, use the code <code>{| class="wikitable sortable collapsible collapsed"</code> in place of <code>{| class="wikitable sortable collapsible"</code>

== Section link to a row ==
To create an [[Help:Link#Section linking (anchors)|anchor for a section link]] to reference a row of a table add an <code>'''id="section link anchor name"'''</code> parameter to the row start <code>'''|-'''</code> or '''<code><nowiki>
|-
</nowiki></code>''':
<nowiki>|- id="section link anchor name"</nowiki>

<code><nowiki>
|- id="section link anchor name"
</nowiki></code>
Note that each anchor names must be different from every other in the page (this includes heading names), to create valid XHTML.

== Row template ==
Regardless of whether wikitable format or HTML is used, the wikitext of the rows within a table, and sometimes even within a collection of tables, has much in common, e.g.:
* the basic code for a table row
* code for color, alignment, and sorting mode
* fixed texts such as units
* special formats for sorting
In that case it can be useful to create a template that produces the syntax for a table row, with the data as parameters. This can have many advantages:
* easily changing the order of columns, or removing a column
* easily adding a new column if many elements of the new column are left blank (if the column is inserted and the existing fields are unnamed, use a named parameter for the new field to avoid adding blank parameter values to many template calls)
* computing fields from other fields, e.g. population density from population and area
* duplicating content and providing span tags with "display:none" for the purpose of having one format for [[Help:Sorting|sorting]] and another for display
* easy specification of a format for a whole column, such as color and alignment

Example:

Using {{pim|help|table/example row template}}
<pre style="display: inline-block;">
{| class="wikitable sortable" border="1"
|-
! scope="col" | a
! scope="col" | b
! scope="col" | a/b
{{help:table/example row template| 50|200}}
{{help:table/example row template| 8| 11}}
{{help:table/example row template|1000| 81}}
|}
</pre>
gives:
{| class="wikitable sortable"
|-
! scope="col" | a
! scope="col" | b
! scope="col" | a/b
{{help:table/example row template| 50|200}}
{{help:table/example row template| 8| 11}}
{{help:table/example row template|1000| 81}}
|}

== Conditional table row ==
{{main|Wikipedia:Conditional tables}}
For a conditional row in a table, we can have:
<pre style="display: inline-block;">
{| class="wikitable" border="1"
<!--
Row one will be shown because the '1' evaluates
to TRUE.
-->
{{ #if:1|{{!}}-
! scope="row" {{!}} row one, column one
<!--
Any {{!}}'s will get evaluated to the pipe
character '|' since the template '!' just
contains '|'.
-->
{{!}}row one, column two}}
<!--
Row two will NOT be shown because the space
between the ':' and the '|' evaluates to FALSE.
-->
{{ #if: |{{!}}-
! scope="row" {{!}} row two, column one
{{!}}row two, column two}}
<!--
Row three will be shown.
-->
|-
! scope="row" {{!}} row three, column one
| row three, column two
|}
</pre>
Which gives the following table: (note how the second row is missing)
{| class="wikitable"
<!-- Row one will be shown because the '1' evaluates to TRUE -->
{{ #if:1|{{!}}-
! scope="row" {{!}} row one, column one
<!-- {{!}}'s get evaluated to the pipe character '|', i.e. template:! just contains '|' -->
{{!}}row one, column two}}
<!-- Row two NOT shown because the space between the ':' and the '|' evaluates to FALSE -->
{{ #if: |{{!}}-
! scope="row" {{!}} row two, column one
{{!}}row two, column two}}
<!-- Row three will be shown -->
|-
! scope="row" {{!}} row three, column one
| row three, column two
|}

== Other table syntax ==
Other types of '''table''' syntax that MediaWiki supports:
# XHTML
# HTML & wiki-<nowiki>
| </nowiki> 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-<nowiki>
| </nowiki> syntax (i.e., unclosed <nowiki>
| </nowiki> and <nowiki>
|-
</nowiki> tags) will not necessarily remain browser-supported in the future, especially on handheld internet-accessible devices.

See also [[w:HTML element#Tables|HTML element#Tables]]. Note however that the <code>thead</code>, <code>tbody</code>, <code>tfoot</code>, <code>colgroup</code>, and <code>col</code> elements are currently not [[Help:HTML in wikitext#Permitted HTML|supported in MediaWiki]].

=== Comparison of table syntax ===
{| class="wikitable"
|
! scope="col" | XHTML
! scope="col" | Wiki-pipe
|-
! scope="row" | Table
| <pre><table></table></pre>
| <pre>{|
|}</pre>
|-
! scope="row" | Caption
| <pre><caption>caption</caption></pre>
| <pre>|+ caption</pre>
|-
! scope="row" | Row
| <pre><tr></tr></pre>
| <pre>|-</pre>
|-
! scope="row" | Data cell
| <pre><td>cell1</td><td>cell2</td>
<td>cell3</td></pre>
| <pre>| cell1 || cell2
| cell3</pre>
|-
! scope="row" | Header cell
| <pre>
<pre><th scope="col">column heading</th></pre><br><pre><th scope="row">row heading</th></pre>
</pre>
| <pre>! scope="col" | column heading</pre><br><pre>! scope="row" | row heading</pre>
|-
! scope="row" rowspan="2" | Sample table
| colspan="2" |
{| style="margin: auto;" border="1" cellspacing="0" cellpadding="3"
|-
| 1||2
|-
| 3||4
|}
|-
| <pre><table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table></pre>
| <pre>{|
| 1 || 2
|-
| 3 || 4
|}</pre>
|- style="vertical-align: top;"
! scope="row" | Pros
|
* Can preview or debug with any XHTML editor
* Can be indented for easier reading
* Well-known
* Insensitive to newlines
* No characters like "|" which can collide with template and parser function syntax
|
* Easy to write
* Easy to read
* Takes little space
* Can be learned quickly
|- style="vertical-align: top;"
! scope="row" | Cons
|
* Tedious
* Takes a lot of space
* Difficult to read quickly
* Debugging more difficult due to tag pairing requirements
* Indented code might not match nesting.
* Confusing newline behaviour as they only occasionally break cells.
|
* Unfamiliar syntax for experienced HTML editors
* Rigid structure
* Cannot be indented for clarity
* HTML tag text may be easier to read than pipes, plus signs, dashes, etc.
* Requires using [[Template:!]] to pass a "|" in a parameter.
* Sensitive to newlines; see [[Help:Newlines and spaces]].
|-
! scope="col" |
! scope="col" | XHTML
! scope="col" | Wiki-pipe
|}
See also [[Template talk:For#Tables]].

== Pipe syntax in terms of the HTML produced ==
The pipe syntax, developed by [[m:User: Magnus Manske|Magnus Manske]], substitutes pipes (<nowiki>|</nowiki>) for HTML. There is an [http://www.uni-bonn.de/~manfear/html2wiki-tables.php 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 <code>||</code> to separate cells on a single line. The parameters are optional.

=== Tables ===
A [[w:Table (HTML)|table]] is defined by
<nowiki>
{| ''params''
|}
</nowiki>
which generates "&lt;table ''params''>&lt;/table>".

=== Rows ===
For each table, an HTML &lt;tr&gt; tag will be generated for the first row. To start a new row, use:
|-
which generates another "&lt;tr&gt;".

Parameters can be added like this:
|- ''params''
which generates "&lt;tr ''params''&gt;".

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

=== Cells ===
Cells are generated either like this:
|cell1
|cell2
|cell3
or like this:
|cell1||cell2||cell3
which both generate "&lt;td&gt;cell1&lt;/td&gt;&lt;td&gt;cell2&lt;/td&gt;&lt;td&gt;cell3&lt;/td&gt;". The "||" equals "newline" + "|".

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

=== Headers ===
Produces a TH, functioning the same way as TD, but with different style. "!" is used instead of the opening "|". "!!" can be used instead of "||". Parameters still use "|", though. Example:
<nowiki>!</nowiki>''params''|cell1

=== Captions ===
A &lt;caption&gt; tag is created by
|+ Caption
which generates the HTML "&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;".

=== Summaries ===
A summary is produced by adding a summary attribute after the start of the table. It can be used by [[screen reader]]s to give visually impaired readers the overall gist of the table, without having to listen to the entire table. For example:
<pre style="overflow:auto;">
{| summary="Artistic renderings of Germania became more triumphant and monumental."
| [[File:Philipp Veit 008.jpg|thumb|upright|alt=Robed woman, seated, with sword on her lap|Philipp Veit, ''Germania'', 1834–36]]
| [[File:Image Germania (painting).jpg|thumb|upright|alt=Robed woman, standing, holding a sword|Philipp Veit, ''Germania'', 1848]]
| [[File:Niederwald memorial 2.JPG|thumb|upright|alt=Monument of robed woman, standing, holding a crown in one hand and a partly sheathed sword in another|Johannes Schilling, ''Germania'', 1871–83]]
|}
</pre>
produces:
{| summary="Artistic renderings of Germania became more triumphant and monumental."
| [[File:Philipp Veit 008.jpg|thumb|upright|alt=Robed woman, seated, with sword on her lap|Philipp Veit, ''Germania'', 1834–36]]
| [[File:Image Germania (painting).jpg|thumb|upright|alt=Robed woman, standing, holding a sword|Philipp Veit, ''Germania'', 1848]]
| [[File:Niederwald memorial 2.JPG|thumb|upright|alt=Monument of robed woman, standing, holding a crown in one hand and a partly sheathed sword in another|Johannes Schilling, ''Germania'', 1871–83]]
|}

== Square monitors ==
To format for a square monitor or window, use a tape measure. Determine the height of your rectangular screen. Using that figure measure under the screen to determine the width your monitor’s screen would be if it were square. Mark that location using ink or tape under the screen. Drag the side of your browser’s window to that location so the window is square based on accurate measurements. Square monitors and reading windows are not able to contain tables and galleries made for rectangular and wide screens. When a table or gallery is wider than the monitor, it makes every line of text wider than the screen as well. The px amounts of the following gallery were determined after measuring the window to make sure it was square:

Type this:

<pre style="display: inline-block;">
{| style="background: transparent; margin: auto;"
| [[File:Some window blinds.JPG|192x155px|thumb|left|Various window shades]]
| [[File:Vert-blinds-2145-rs.jpg|192x170px|thumb|left|Vertical blinds]]
| [[File:Gardine.jpg|192x155px|thumb|left|This is not a blind]]
|}

{| style="background: transparent; margin: auto;"
| [[File:Vorhang.jpg|192x155px|thumb|left|Solid shade]]
| [[File:Jalousie-1.jpg|328x55px|thumb|left|Horizonal blinds]]
|}

{| style="background: transparent; margin: auto;"
| [[File:Some window blinds.JPG|205px|thumb|left|Shade, shutters; vertical & horizontal blinds.]]
| [[File:Miniblinds detail of mechanism.jpg|388px|thumb|left|<!--
-->Detail of turning rod (blind stick) attachment on miniblinds]]
|}
</pre>

For this:
{| style="background:none; margin: auto;"
|-
| [[File:Some window blinds.JPG|192x155px|thumb|left|Various window shades]]
| [[File:Vert-blinds-2145-rs.jpg|192x170px|thumb|left|Vertical blinds]]
| [[File:Gardine.jpg|192x155px|thumb|left|This is not a blind]]
|}

{| style="background:none; margin: auto;"
|-
| [[File:Vorhang.jpg|192x155px|thumb|left|Solid shade]]
| [[File:Jalousie-1.jpg|328x55px|thumb|left|Horizonal blinds]]
|}

{| style="background:none; margin: auto;"
|-
| [[File:Some window blinds.JPG|205px|thumb|left|Shade, shutters; vertical & horizontal blinds.]]
| [[File:Miniblinds detail of mechanism.jpg|388px|thumb|left|<!--
-->Detail of turning rod (blind stick) attachment on miniblinds]]
|}

== Vertically oriented column headers ==
Sometimes it is desirable (such as in a table predominantly made of numbers) to rotate text such that it proceeds from top to bottom or bottom to top instead of from left to right or right to left. Currently, browser support for this type of styling as a component of HTML or CSS is sporadic (Internet Explorer is one of the few browsers that supports this in cascading stylesheets, albeit in a non-standard way). An alternative solution that works in most if not all browsers is to use images in place of the text. For instance, the following table uses SVG images instead of text to produce the rotated column headings:

{| class="wikitable" style="text-align: center;"
|- style="vertical-align: bottom;"
! style="width:3em;" | [[File:wpvg hd date page.svg|link=]]
! style="width:3em;" | [[File:wpvg vg project.svg|link=Wikipedia:WikiProject Video games]]
! style="width:3em;" | [[File:wpvg vg talk.svg|link=Wikipedia talk:WikiProject Video games]]
! style="width:3em;" | [[File:wpvg vg portal.svg|link=Portal:Video games]]
! style="width:3em;" | [[File:wpvg vg article guidelines.svg|link=Wikipedia:WikiProject Video games/Article guidelines]]
! style="width:3em;" | [[File:wpvg vg templates.svg|link=Wikipedia:WikiProject Video games/Templates]]
! style="width:3em;" | [[File:wpvg vg sources.svg|link=Wikipedia:WikiProject Video games/Sources]]
! style="width:3em;" | [[File:wpvg vg assessment.svg|link=Wikipedia:WikiProject Video games/Assessment]]
! style="width:3em;" | [[File:wpvg vg cleanup.svg|link=Wikipedia:WikiProject Video games/Cleanup]]
! style="width:3em;" | [[File:wpvg vg requests.svg|link=Wikipedia:WikiProject Video games/Requests]]
|-
! 05/08
| 4266 || 7828 || 7282 || 1105 || 224 || 161 || 916 || 506 || 231
|-
! 04/08
| 4127 || 6190 || 6487 || 1139 || 241 || 205 || 1165 || 478 || 301
|}

Normally, one problem with this approach is that readers are directed to different pages when they click on the images. To eliminate this problem—or to direct readers to a ''different'' page—you can use the <code>link</code> parameter. A column-header can be coded as follows:

<pre style="display: inline-block;">
<nowiki>
! style="width:3em;" | [[File:wpvg vg project.svg|link=xxxx]]
</nowiki>
</pre>
The image will wikilink to article "xxxx".

By setting the link to an empty string (e.g. <code><nowiki>[[File:wpvg hd date page.svg|link=]]</nowiki></code>), no navigation will occur when visitors click on an image. Note that it might also be a good idea to color the image text blue if you are using the images as links. Also, SVG is the preferred image format in this case because it can be re-scaled to any size without producing artifacts.

== Wikitable as image gallery ==
<!-- #REDIRECT [[Template:Ph:Reader]] {{R unprintworthy}} -->
:''This section is local to Wikipedia (hard-coded here now).''
A wikitable can be used to display side-by-side images, in the manner of an image gallery (formatted by "&lt;gallery>"), but with larger images and less vacant area around photos.

A simple framed gallery can be formatted using class="wikitable" to generate the minimal thin-lines around images/photos within the table:

<nowiki>
{| class="wikitable" border="1"
|-
|<!--column1-->[[File:Worms 01.jpg|265px]]
|<!--column2-->[[File:Worms Wappen 2005-05-27.jpg|235px]]
|-
|<!--column1-->Nibelungen Bridge to Worms<br />across the [[Rhine]]
|<!--column2-->Worms and its sister cities
|}<!--end wikitable--></nowiki>

Note the result below (with thin-lined cells):
{| class="wikitable"
|-
|<!--column1-->[[File:Worms 01.jpg|265px]]
|<!--column2-->[[File:Worms Wappen 2005-05-27.jpg|235px]]
|-
|<!--column1-->Nibelungen Bridge to Worms<br />across the [[Rhine]]
|<!--column2-->Worms and its sister cities
|}
Another issue about the standard "&lt;gallery>" tag, in 2007 to 2008, was that it put 4 images per line, overrunning the right margin of a wiki article displayed in portrait-style width (like 800x600), unless the gallery had only 3 images. However, a wikitable uses typical image-links with sizes, such as <nowiki>"[[</nowiki>Image:XXX.jpg|130px]]" so 4 images could be displayed on a wikitable line within a 600px width (for 800&nbsp;×&nbsp;600 resolution screens).

<nowiki>
{| class="wikitable" border="1"
|-
|<!--col1-->[[File:Worms 01.jpg|130px]]
|<!--col2-->[[File:Worms Wappen 2005-05-27.jpg|125px]]
|<!--col3-->[[File:Liberty-statue-with-manhattan.jpg|125px]]
|<!--col4-->[[File:New-York-Jan2005.jpg|125px]]
|-
|<!--col1-->Nibelungen Bridge to Worms
|<!--col2-->Worms and its sister cities
|<!--col3-->Statue of Liberty
|<!--col4-->New York City
|}<!--end wikitable--></nowiki>

{| class="wikitable"
|-
|<!--col1-->[[File:Worms 01.jpg|130px]]
|<!--col2-->[[File:Worms Wappen 2005-05-27.jpg|125px]]
|<!--col3-->[[File:Liberty-statue-with-manhattan.jpg|125px]]
|<!--col4-->[[File:New-York-Jan2005.jpg|115px]]
|-
|<!--col1-->Nibelungen Bridge to Worms
|<!--col2-->Worms and its sister cities
|<!--col3-->Statue of Liberty
|<!--col4-->New York City
|}
Another advantage about wikitable images, compared to "&lt;gallery>" formatting, is the ability to "square" each image when similar heights are needed, so consider putting 2-number image sizes (such as "199x95px"), where the 2nd number limits height:

<nowiki>
{| class="wikitable" border="1"
|-
|<!--col1-->[[File:Liberty-statue-with-manhattan.jpg|199x95px]]
|<!--col2-->[[File:New-York-Jan2005.jpg|199x95px]]
|<!--col3-->[[File:Gold star on blue.gif|199x95px]]
|<!--col4-->[[File:Worms 01.jpg|100x95px]]<!--smaller-->
|-
|<!--col1-->Statue of Liberty
|<!--col2-->New York City
|<!--col3-->Star on blue
|<!--col4-->Bridge to Worms
|}<!--end wikitable--></nowiki>

Note the 3 images sized "199x95px" appear identical height, of 95px (4th image purposely smaller). The "95px" forces height, while "199x" fits the various widths (could even be "999x"):
{| class="wikitable"
|-
|<!--col1-->[[File:Liberty-statue-with-manhattan.jpg|199x95px]]
|<!--col2-->[[File:New-York-Jan2005.jpg|199x95px]]
|<!--col3-->[[File:Gold star on blue.gif|199x95px]]
|<!--col4-->[[File:Worms 01.jpg|100x95px]]<!--smaller-->
|-
|<!--col1-->Statue of Liberty
|<!--col2-->New York City
|<!--col3-->Star on blue
|<!--col4-->Bridge to Worms
|}
Therefore, the use of size "199x95px" (or "999x95px") produces the auto-height-sizing beyond the "&lt;gallery>" tag, and with the option to set taller thumbnails ("199x105px"), or even to have some images purposely smaller than other images of "95px" height. A very short height ("70px") allows many more images across the table:

<nowiki>
{| class="wikitable" border="1"
|-
|<!--col1-->[[File:Liberty-statue-with-manhattan.jpg|199x70px]]
|<!--col2-->[[File:Gold star on blue.gif|199x70px]]
|<!--col3-->[[File:New-York-Jan2005.jpg|199x70px]]
|<!--col4-->[[File:Gold star on deep red.gif|199x70px]]
|<!--col5-->[[File:Worms 01.jpg|199x70px]]<!--same height-->
|<!--col6-->[[File:Gold star on blue.gif|199x70px]]
|}</nowiki>
The above wikitable-coding produces the result below, of 6 columns:
{| class="wikitable"
|-
|<!--col1-->[[File:Liberty-statue-with-manhattan.jpg|199x70px]]
|<!--col2-->[[File:Gold star on blue.gif|199x70px]]
|<!--col3-->[[File:New-York-Jan2005.jpg|199x70px]]
|<!--col4-->[[File:Gold star on deep red.gif|199x70px]]
|<!--col5-->[[File:Worms 01.jpg|199x70px]]<!--same height-->
|<!--col6-->[[File:Gold star on blue.gif|199x70px]]
|}

Once images have been placed in a wikitable, control of formatting can be adjusted when more images are added.

=== Shifting/centering ===
Images within a wikitable can be shifted by inserting non-breaking spaces ("&amp;nbsp;") before or after the image-link ("&amp;nbsp;[<font/>[Image:]]"). However, auto-centering simply requires use of center-tags to be placed around an image-link for centering in a cell <nowiki>("<center>[[File:..]]</center>")</nowiki>.

In the example below, note how Col2 uses &lt;center>, but Col3 uses "&amp;nbsp;":
<nowiki>
{| class="wikitable" border="1"
|-
|<!--Col1-->[[File:Domtoren vanaf Brigittenstraat.jpg|299x125px]]
|<!--Col2--><center>[[File:Utrecht 003.jpg|299x125px]]</center>
|<!--Col3-->&amp;nbsp;[[File:Uitzicht--Domtoren.jpg|299x125px]]&amp;nbsp;
|-
|<!--Col1-->Dom tower from Brigittenstraat
|<!--Col2-->Cloister garth of the Utrecht Dom Church
|<!--Col3-->&amp;nbsp;&amp;nbsp;<small>View from bell tower</small>
|}</nowiki>
The above coding generates the table below: note the middle garden image is centered (but not the left image), and the right image has 2 spaces before " &nbsp;View...":
{| class="wikitable" <!-- LIVE -->
|-
|<!--Col1-->[[File:Domtoren vanaf Brigittenstraat.jpg|299x125px]]
|<!--Col2--><div class="center">[[File:Utrecht 003.jpg|299x125px]]</div>
|<!--Col3-->&nbsp;[[File:Uitzicht vanaf de Domtoren.jpg|299x125px]]&nbsp;
|-
|<!--Col1-->Dom tower from Brigittenstraat
|<!--Col2-->Cloister garth of the Utrecht Dom Church
|<!--Col3-->&nbsp;&nbsp;<small>View from bell tower</small>
|}
Also note that the tag "&lt;small>" made a smaller text-size caption. However, fonts also can be sized by percent (style="font-size: 87%;"), where the actual percent-size as displayed depends on the various sizes allowed for a particular font.
<pre>
| style="font-size: 87%;" | View from bell tower
</pre>
The column attribute, above, uses "style=" to set the font-size for the caption, following the 2nd vertical-bar "|".

A font-size: 65% is very small, while style="font-size: 87%;" is a mid-size font, larger than the tag ''small''.

=== Speed/transfer rates ===
Actual transfer/display speeds depend on individual files. From 2007 to March 2009 some serious flaws existed in the thumbnailing process when combined with the gallery-display, making thumbnails sometimes larger than the originals. For this reason some users explicitly used tables instead of the gallery tag. However, these issues are fixed as of March 2009.

== Generate a chart with a table ==
{{main|meta:Visualizer for Wikimedia projects}}
Using {{t|visualizer}} or another template that uses {{t|metavisualizer}}.

== Converting spreadsheet to wikitable format ==
To convert from spreadsheets such as Gnumeric, MS Excel or OpenOffice.org Calc, you can use the [http://excel2wiki.net/wikipedia.php Copy & Paste Excel-to-Wiki] converter<!-- dead link: or you can save your spreadsheets as [[.csv]] and use the [http://toolserver.org/~al/data2mwGenerators/csv2wikitable.php csv2wikitable] converter-->.

[http://area23.brightbyte.de/csv2wp.php csv2wp] – converts [[w:comma-separated values|comma-separated values]] (CSV) format to pipe syntax. You may use this to import tables from Excel etc. ([[:de:Benutzer:Duesentrieb/csv2wp (en)|more information]])

== Tables and WYSIWYG ==
Due to the complexity of wikimarkup (especially tables), a common question is if there is any [[WYSIWYG|visual editor]] to make creating and modifying tables easier. Unfortunately at the moment no such editor exists, however it is possible to create a table with a [[HTML editor]] (like [[Adobe Dreamweaver]]) and then copy the html code generated by this into the page.

It is possible in the future that a WYSIWYG editor will be adopted (there has been much discussion about this in the past, however there are many technical hurdles that need to be solved). For the more technically inclined/adventurous tools such as [[mw:WYSIFTW|WYSIFTW]] exist, however they do not incorporate the complete WYSIWYG experience and currently do not support tables (although they may do so in the future).

== See also ==
* [[Help:Wikitable]]
* [[Wikipedia:Manual of Style/Tables]]
* [[Wikipedia:How to make a table in Wikipedia]]
* [[mw:Table]]
* [[mw:Simplified table syntax]]
* [[m:Wiki markup tables]]
* [[m:Table background colors]]
* [[Help:Sorting]]
* [[m:Help:Sorting]]
* [[User:Dcljr/Tables]]
* [[w:Table (HTML)]]
* [[m:Help:Template#A parameter value containing a pipe character]]
* Examples:
** [[Template:Chess diagram|Chess board]]
** [[Template:Goban|Go board]]
** [[m:Template talk:Square 8x8 pentomino example|Square 8&nbsp;×&nbsp;8 pentomino example]]
* [[commons:Commons:Convert tables and charts to wiki code|Commons:Convert tables and charts to wiki code]]
* [[commons:Commons:Chart and graph resources|Commons:Chart and graph resources]]
* Cleanup template {{tl|List to table}} and its category [[:Category:Articles requiring tables]]

== External links ==
* [[:de:Wikipedia:Helferlein/VBA-Macro for EXCEL tableconversion]] published in German-Wikipediaproject (English instructions included)
* [http://www.cnic.org/html2mediawiki.html HTML tables to wiki converter at cnic.org]
* [http://www.uni-bonn.de/~manfear/html2wiki-tables.php HTML tables to wiki converter at uni-bonn.de]
* [http://diberri.dyndns.org/html2wiki.html HTML tables to wiki converter at diberri.dyndns.org]
* [http://pywikipediabot.sourceforge.net/ pywikipediabot] (can convert HTML tables to wiki)
* [http://search.cpan.org/~diberri/ HTML-WikiConverter] Various versions and languages
* [http://en.wikibooks.org/wiki/Editing_Wikitext/Tables Making Wiki Tables] with good examples
* [http://en.wikibooks.org/wiki/Editing_Wikitext/Tables_Ready_to_Use Wiki and HTML Tables Ready to Use]: A selection of tables and their Wiki/HTML code
* [http://www.w3.org/TR/css3-color/ Table of CSS color names and HEX codes]
Bureaucrats, developer, smwadministrator, Administrators
10,246

edits