This code:
{| class="wikitable" border="1"
|+ Muscarinic Affinity Constants
! *|| M1 || M2
|-
| Pirenzepine: ||align="center"| 8.15 || align="center"|6.5
|-
| AF-DX 384: || align="center"|7.4 ||align="center"| 8.6
|-
|}
Makes this:
| * | M1 | M2 |
|---|---|---|
| Pirenzepine: | 8.15 | 6.5 |
| AF-DX 384: | 7.4 | 8.6 |
{| style="width:75%; height:200px" border="1"
|-
| abc || def || ghi
|- style="height:100px"
| jkl || style="width:200px" |mno || pqr
|-
| stu || vwx || yz
|}
| abc | def | ghi |
| jkl | mno | pqr |
| stu | vwx | yz |
{| border="1" cellpadding="2"
!width="50"|Name
!width="225"|Effect
!width="225"|Games Found In
|-
|Poké Ball || Regular Poké Ball || All Versions
|-
|Great Ball || Better than a Poké Ball || All Versions
|}
| Name | Effect | Games Found In |
|---|---|---|
| Poké Ball | Regular Poké Ball | All Versions |
| Great Ball | Better than a Poké Ball | All Versions |
{| 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
|}
| This column is 100 points wide | This column is 200 points wide | This column is 300 points wide |
| blah | blih | bluh |
{| cellpadding="2" style="border:1px solid darkgray;"
!width="140"|Left
!width="150"|Middle
!width="130"|Right
|- border=0
| [[Image:StarIconBronze.png|120px]]
| [[Image:StarIconGold.png|120px|Caption when mouse-over image]]
| [[Image:StarIconGreen.png|120px|Green stellar icon]]
|- align=center
|Bronze star || Gold star || Green star
|}
| Left | Middle | Right |
|---|---|---|
| | | |
| Bronze star | Gold star | Green star |
{| cellpadding="2" style="border:1px solid darkgray;"
!width="140"|Left
!width="150"|Middle
!width="130"|Right
|- align=center
| style="border:1px solid blue;"|
[[Image:StarIconBronze.png|120px]]
| style="border:1px solid #777777;"|
[[Image:StarIconGold.png|120px|Caption when mouse-over image]]
| style="border:1px solid #22AA55;"|<!--greenish border-->
[[Image:StarIconGreen.png|120px|Green stellar icon]]
|- align=center
|Bronze star || Gold star || Green star
|}
| Left | Middle | Right |
|---|---|---|
| Bronze star | Gold star | Green star |
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:
{|
| A
| B
|-
| C
| D
|}
{|
| A || B
|-
| C || D
|}
What it looks like in your browser:
A B C D
The wiki markup code:
{| class="wikitable" style="text-align:center; width:200px; height:200px" border="1"
|+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
|}
What it looks like in your browser (see: Help:User_style):
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
Two ways of specifying color of text and background for a single cell are as follows. The first form is preferred:
The wiki markup code:
{|
| style="background:red; color:white" | abc
| def
| bgcolor="red" | <font color="white"> ghi </font>
| jkl
|}
What it looks like in your browser:
abc def ghi jkl
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:
{| style="background:yellow; color:green"
|-
| abc || def || ghi
|- style="background:red; color:white"
| jkl || mno || pqr
|-
| stu || style="background:silver" | vwx || yz
|}
What it looks like in your browser:
abc def ghi jkl mno pqr stu vwx yz
To make the table blend in with the background, use style="background:none" or style="background:transparent". (Warning: style="background:inherit", does not work with some browsers, including IE6!)
To force a cell to match one of the default colors of the class="wikitable" template, use style="background:#f2f2f2" for the darker header, and style="background:#f9f9f9" for the lighter body.
See : style, background, list of colors, web colors
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:
{| style="width:75%; height:200px" border="1"
|-
| abc || def || ghi
|- style="height:100px"
| jkl || style="width:200px" |mno || pqr
|-
| stu || vwx || yz
|}
What it looks like in your browser:
abc def ghi jkl mno pqr stu vwx yz
Note that style="inline CSS" has no effect with some browsers. If compatibility is important, equivalent older constructs like width="75%" should work on more browsers.
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.
The wiki markup code:
{| border="1" cellpadding="2"
!width="50"|Name
!width="225"|Effect
!width="225"|Games Found In
|-
|Poké Ball || Regular Poké Ball || All Versions
|-
|Great Ball || Better than a Poké Ball || All Versions
|}
Name Effect Games Found In Poké Ball Regular Poké Ball All Versions Great Ball Better than a Poké Ball All Versions
To set column widths in a table without headers, specify the width in the first cell for each column, like this:
{| 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
|}
This column is 100 points wide This column is 200 points wide This column is 300 points wide blah blih bluh
One application of setting the widths is aligning columns of consecutive tables:
| Country | Capital |
|---|---|
| The Netherlands | Amsterdam |
| Country | Capital |
|---|---|
| France | Paris |
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):
{| cellpadding="2" style="border:1px solid darkgray;"
!width="140"|Left
!width="150"|Middle
!width="130"|Right
|- border=0
| [[Image:StarIconBronze.png|120px]]
| [[Image:StarIconGold.png|120px|Caption when mouse-over image]]
| [[Image:StarIconGreen.png|120px|Green stellar icon]]
|- align=center
|Bronze star || Gold star || Green star
|}
Note the bottom-row texts are centered by "align=center" while star-images were not centered.
| Left | Middle | Right |
|---|---|---|
| | | |
| 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:
{| cellpadding="2" style="border:1px solid darkgray;"
!width="140"|Left
!width="150"|Middle
!width="130"|Right
|- align=center
| style="border:1px solid blue;"|
[[Image:StarIconBronze.png|120px]]
| style="border:1px solid #777777;"|
[[Image:StarIconGold.png|120px|Caption when mouse-over image]]
| style="border:1px solid #22AA55;"|<!--greenish border-->
[[Image:StarIconGreen.png|120px|Green stellar icon]]
|- align=center
|Bronze star || Gold star || Green star
|}
Note only the image cells, here, have individual borders, not the text.
| Left | Middle | Right |
|---|---|---|
| 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.
Never use class="wikitable" without also using border="1", or you will produce accessibility problems.
By default data in tables is vertically centrally aligned, which results in odd-looking layouts like this:
| Row heading | 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. | short text |
| Row heading | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. | 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:
{| border="1" cellpadding="2" width=400px
|-valign="top"
|width="10%"|'''Row heading'''
|width="70%"|A longer piece of text. Lorem ipsum...
|width="20%"|short text
|-valign="top"
|'''Row heading'''
|Excepteur sint occaecat...
|short text
|}
| Row heading | 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. | short text |
| Row heading | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 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. | short text |
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".
Here's a more advanced example, showing some more options available for making up tables. Note however that with colspan and rowspan sorting does not work properly anymore.
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.
The wiki markup code:
{| 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
|
| 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="150px" | [[Image:Wiki.png]]
| align="center" width="150px" | [[Image: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 Wikimedia logos
|}
|}
What it looks like in your browser:
An example table First header Second header upper left right side
lower left lower middle
A table in a table ![]()
![]()
Two Wikimedia logos
The wiki markup coding:
This paragraph is before the table. Lorem ipsum dolor sit
amet, consectetur adipisicing elit, sed do eiusmod...
{| align="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.
What it looks like in your browser:
This paragraph is before the table. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod...
Col 1, row 1 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.
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:
{| style="float:right; border:1px solid #BBB;margin:.46em 0 0 .2em"
|- style="font-size:86%"
| valign="top" |[[Image:StarIconGreen.png|180px]]<!--
--><br> Temple of [[Bel (mythology)|Bel]] (floating).
|}
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).
| Infobox A | |
|---|---|
| This sample infobox shows how the floating image-box aligns toward the center. |
Temple of Bel (floating). |
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.
...by float:right |
...images wrap... |
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.
Five 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
{| border="1"
| α
| align="center" | cell2
{| border="2" style="background:#ABCDEF;" <!-- The nested table must be on a new line -->
| NESTED
|-
| TABLE
|}
| valign="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
|}
|}
What it looks like in your browser
| α | cell2
| the original table again |
|
|
Wiki markup
{| border="1" cellpadding="5" cellspacing="0"
|-
| Column 1 || Column 2 || Column 3
|-
| rowspan="2"| A
| colspan="2" align="center"| B
|-
| C <!-- column 1 occupied by cell A -->
| D
|-
| E
| rowspan="2" colspan="2" align="center"| F
|-
| G <!-- column 2+3 occupied by cell F -->
|-
| colspan="3" align="center"| H
|}
What it looks like in your browser
| Column 1 | Column 2 | Column 3 |
| A | B | |
| C | D | |
| E | F | |
| G | ||
| H | ||
Note that using rowspan="2" for cell G combined with rowspan="3" 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 to fill an empty cell with dummy content.
Centered tables can be achieved, but they will not "float"; that is to say, no text will appear to either side. The trick is {| style="margin: 1em auto 1em auto"
Wiki markup
{| class="wikitable" style="margin: 1em auto 1em auto" border="1"
|+ '''Cells left-aligned, table centered'''
! Duis || aute || irure
|-
| dolor || in reprehenderit || in voluptate velit
|-
| esse cillum dolore || eu fugiat nulla || pariatur.
|}
What it looks like in your browser
| Duis | aute | irure |
|---|---|---|
| dolor | in reprehenderit | in voluptate velit |
| esse cillum dolore | eu fugiat nulla | pariatur. |
At the start of a cell, add your parameter followed by a single pipe. For example width="300"| will set that cell to a width of 300 pixels. To set more than one parameter, leave a space between each one, as follows:
{| style="color:white"
|-
| bgcolor="red"|cell1 || width="300" bgcolor="blue"|cell2
| bgcolor="green"|cell3
|}
What it looks like in your browser:
| cell1 | cell2 | cell3 |
In the first line of table code, after the "{|", instead of specifying a style directly, you can also specify a CSS class. The style for this class can be specified in various ways:
Instead of remembering table parameters, you just include an appropriate style class after the {|. 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:
|
| |||||||||||||||||||||||||
| becomes this: | ||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||
simply by replacing inline CSS for the table by class="wikitable". This is because the wikitable class in MediaWiki:Common.css contains a number of table.wikitable 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
{| class="wikitable" style="font-style:italic; font-size:120%; border:3px dashed red;" border="1"
|+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
|}
What it looks like in your browser
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
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 <big> instead of "font-size:120%", or Wiki markup like ''text'' instead of "font-style:italic".
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:
{| class="wikitable collapsible collapsed" border="1"
! Header
|-
|Content which starts hidden
|-
|more hidden content
|}
Gives:
| Header |
|---|
| Content which starts hidden |
| more hidden content |
A wikitable can be used to display side-by-side images, in the manner of an image gallery (formatted by "<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:
{| class="wikitable" border="1"
|-
|<!--column1-->[[Image:StarIconGreen.png|265px]]
|<!--column2-->[[Image:StarIconGreen.png|235px]]
|-
|<!--column1-->Nibelungen Bridge to Worms<br/>across the [[Rhine]]
|<!--column2-->Worms and its sister cities
|}<!--end wikitable-->
Note the result below (with thin-lined cells):
| Nibelungen Bridge to Worms across the Rhine | Worms and its sister cities |
Another issue about the standard "<gallery>" tag, in 2007-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 "[[Image:XXX.jpg|130px]]" so 4 images could be displayed on a wikitable line within a 600px width (for 800x600 resolution screens).
{| class="wikitable" border="1"
|-
|<!--col1-->[[Image:StarIconGreen.png|130px]]
|<!--col2-->[[Image:StarIconGreen.png|125px]]
|<!--col3-->[[Image:StarIconGreen.png|125px]]
|<!--col4-->[[Image:StarIconGreen.png|125px]]
|-
|<!--col1-->Nibelungen Bridge to Worms
|<!--col2-->Worms and its sister cities
|<!--col3-->Statue of Liberty
|<!--col4-->New York City
|}<!--end wikitable-->
| Nibelungen Bridge to Worms | Worms and its sister cities | Statue of Liberty | New York City |
Another advantage about wikitable images, compared to "<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:
{| class=wikitable border="1"
|-
|<!--col1-->[[Image:StarIconGreen.png|199x95px]]
|<!--col2-->[[Image:StarIconGreen.png|199x95px]]
|<!--col3-->[[Image:StarIconGreen.png|199x95px]]
|<!--col4-->[[Image:StarIconGreen.png|100x95px]]<!--smaller-->
|-
|<!--col1-->Statue of Liberty
|<!--col2-->New York City
|<!--col3-->Star on blue
|<!--col4-->Bridge to Worms
|}<!--end wikitable-->
Images within a wikitable can be shifted by inserting non-breaking spaces (" ") before or after the image-link (" [<font/>[Image:]]"). However, auto-centering simply requires use of center-tags to be placed around an image-link for centering in a cell ("<center>[[Image:..]]</center>").
In the example below, note how Col2 uses <center>, but Col3 uses " ":
{| class=wikitable border="1"
|-
|<!--Col1-->[[Image:StarIconGreen.png|299x125px]]
|<!--Col2--><center>[[Image:StarIconGreen.png|299x125px]]</center>
|<!--Col3--> [[Image:StarIconGreen.png|299x125px]]
|-
|<!--Col1-->Dom tower from Brigittenstraat
|<!--Col2-->Cloister garth of the Utrecht Dom Church
|<!--Col3--> <small>View from bell tower</small>
|}