MOLLER Collaboration Meetings

From Hall A Wiki
Revision as of 19:17, 16 September 2010 by Crowder (Talk | contribs) (New page: {{for|basic use of a wikitable|Help:Wikitable}} {{Wiki markup}} A '''wikitable''' is an arrangement of columns and rows used to organize and position data. Tables are useful, and there ar...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Template:For Template:Wiki markup

A wikitable is an arrangement of columns and rows used to organize and position data. Tables are useful, and there are many ways and tricks that can be used. This page gives you information about syntax to build wikitables in Wikipedia.

Using the toolbar

To automatically insert a table, click File:Button insert table.png (Insert a table) on the edit toolbar. If "Insert a table" is not on the toolbar follow these directions to add it.

The following text is inserted when Insert a table is clicked:

{| class="wikitable"
|-
! header 1
! header 2
! header 3
|-
| row 1, cell 1
| row 1, cell 2
| row 1, cell 3
|-
| row 2, cell 1
| row 2, cell 2
| row 2, cell 3
|}
Header 1 Header 2 Header 3
row 1,cell 1 row 1, cell 2 row 1, cell 3
row 2,cell 1 row 2, cell 2 row 2, cell 3
row 3,cell 1 row 3, cell 2 row 3, cell 3

The sample text ("header 1" or "row 1, cell 1") is to be replaced with actual data.</div>

Pipe syntax tutorial

Column heading 1 Column heading 2 Column heading 3
Row heading 1 Cell 2 Cell 3
Row heading A Cell B Cell C

Although HTML table syntax also works, special wikicode can be used as a shortcut to create a table. The pipe (vertical bar) codes function exactly the same as HTML table markup, so a knowledge of HTML table code will help in understanding pipe code. The shortcuts are as follows:

  • The entire table is encased with curly brackets and a vertical bar character (a pipe). So use {| to begin a table, and |} to end it. Each one needs to be on its own line:
{|
  table code goes here
|}
  • An optional table caption is included with a line starting with a vertical bar and plus sign "|+" and the caption after it:
{|
|+ caption
  table code goes here
|}
  • To start a new table row, type a vertical bar and a hyphen on its own line: "|-". The codes for the cells in that row will start on the next line.
{|
|+ The table's caption
|-
  row code goes here
|-
  row code goes here
|}
  • Type the codes for each table cell in the next row, starting with a bar:
{|
|+ The table's caption
|-
| cell codes go here
|-
| cells in the next row go here
| more cells in the same row here
|}
  • Cells can be separated with either a new line and new bar, or by a double bar "||" on the same line. Both produce the same output:
{|
|+ The table's caption
|-
|Cell 1 || Cell 2 || Cell 3
|-
|Cell A
|Cell B
|Cell C
|}
  • If you use single bars, then what might appear to be the first cell is in fact a format modifier applied to the cell, and the rest of your "cells" will be merged into one:
{| border="1"
|-
|format modifier (not displayed) |These all  |(including the pipes) |go into  |the first cell
|}

which is probably not what you want:

These all |(including the pipes)|go into |the first cell

However, the format modifier is useful:

{| border="1"
|-
| Cell 1 (no modifier — not aligned)
|-
| align="right" | Cell 2 (right aligned)
|}
Cell 1 (no modifier — not aligned)
Cell 2 (right aligned)

Just remember: no more than 2 single pipes on a line!

  • a row of column headings is identified by using "! scope="col" |" instead of "|", and using "!! scope="col" |" instead of "||". Header cells typically render differently from regular cells, depending on the browser. They are often rendered in a bold font and centered.
{|
|+ The table's caption
! scope="col" | Column heading 1 
! scope="col" | Column heading 2 
! scope="col" | Column heading 3
|-
| Cell 1 || Cell 2 || Cell 3
|-
| Cell A
| Cell B
| Cell C
|}
  • the first cell of a row is identified as a row heading by starting the line with "! scope="row" |" instead of "|", and starting subsequent data cells on a new line.
{|
|+ 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
|}
  • Optional parameters can modify the behavior of cells, rows, or the entire table. For instance, a border could be added to the table:
{| border="1"
|+ The table's caption
! 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 final table would display like this:

The table's caption
Column heading 1 Column heading 2 Column heading 3
Row heading 1 Cell 2 Cell 3
Row heading A Cell B Cell C

The table parameters and cell parameters are the same as in HTML, see http://www.w3.org/TR/html401/struct/tables.html#edef-TABLE and Table (HTML). However, the thead, tbody, tfoot, colgroup, and col elements are currently not supported in MediaWiki.

A table can be useful even if none of the cells have content. For example, the background colors of cells can be changed with cell parameters, making the table into a diagram, like 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 &nbsp; as content to ensure that the cells are displayed. To show a visible pipe in a cell, use <nowiki>|</nowiki> or &#124;.

With colspan and rowspan cells can span several columns or rows, see the Mélange example below. However, this has the disadvantage that sorting does not work properly anymore.

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:


{|
| A
| B
|-
| C
| D
|}

{|
| A || B
|-
| C || D
|}

What it looks like in your browser:

A B
C D

Multiplication table

Here is the wiki markup code:

{| class="wikitable" style="text-align: center; width: 200px; height: 200px;"
|+ 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
|}

and 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

Color; scope of parameters

Two ways of specifying 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:


{|
| 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

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:


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

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 wrap-around of text is forced.

The wiki markup code:


{| border="1" cellpadding="2"
! scope="col" width="50" | Name
! scope="col" width="225" | Effect
! scope="col" 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


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 style=white-space:nowrap in a non-header cell on the longest/widest cell to affect the entire column.

Before:

Episode Date 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:

Episode Date 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.

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):


{| 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
|}

Note the bottom-row texts are centered by 'align="center"' while star-images were not centered.

Left Middle Right
120px Caption when mouse-over image Green stellar icon
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;"|
[[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
|}

Note only the image cells, here, have individual borders, not the text.

Left Middle Right

120px

Caption when mouse-over image

Green stellar icon

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:

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="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
|}

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

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

Mélange

Note: This example is not 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'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
| &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
|}
|}

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
File:Wiki.png File:Wiki.png

Two Wikipedia logos

Floating table

The wiki markup coding:


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.

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.

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:


{| 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).
|}

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.
180px
 Temple of Bel  (floating).
File:DuraEuropos-TempleOfBel.jpg
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.

105px
...by float: right
105px
...images wrap...
105px
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 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

{| border="1"
| &alpha;
| style="text-align: center;"| cell2
{| border="2" style="background: #ABCDEF;" <!-- The nested table must be on a new line -->
| 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
|}
|}

What it looks like in your browser

α cell2
NESTED
TABLE
the original table again
A
B B
C
D

Combined use of COLSPAN and ROWSPAN

Wiki markup


{| 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
|}

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 &nbsp; 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 {| style="margin: 1em auto 1em auto;"

Wiki markup


{| 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.
|}

What it looks like in your browser

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

Tiny tables within a text line

For years in HTML, a table has always forced an implicit line-wrap (or line-break), so to keep a table within a line, the work-around is to put all text into a table, then embed a table-within-a-table, using the outer table to force the whole line to stay together. Consider the following examples:

Wikicode (showing table forces line-break):
* This is a test table here <table style="border: 1px solid black"><tr><td>HELLO WORLD</table> followed by this text afterward.
Result:
  • This is a test table here
    HELLO WORLD
    followed by this text afterward.
Wikicode (table-within-table):
* <table style="background-color: #fafeff"><tr><td>This is a test table here<td><table height=11px><tr><td style="border: 1px solid black; font-size:60%">HELLO WORLD</table></td><td>followed by this text afterward.</table> This line is more text after the outer table.
Result:
  • This is a test table here
    HELLO WORLD
    </td><td>followed by this text afterward.</table> This line is more text after the outer table.

    Use style="font-size:60%" to shrink the text within the box. However, the small text could be replaced with small images (aligned inside the inner table). The outer table is for one line only, so to make a 2nd line appear even, the exact length of line 1 must be pre-determined, to match the length of other lines.

    Decimal point alignment

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

    
    {| cellpadding="0" cellspacing="0"
    | align="right" | 432 || .1
    |-
    | align="right" | 43 || .21
    |-
    | align="right" | 4 || .321
    |}
    
    

    What it looks like in your browser:

    432 .1
    43 .21
    4 .321

    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:

    
    {| 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
    |}
    |}
    
    

    What it looks like in your browser:

    432 .1
    43 .21
    4 .321

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

    432.1
     43.21
      4.321
    

    Style classes

    See also Help:User style.

    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:

    • in the software itself, per skin (for example the class 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 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 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:

    {| cellpadding="2"
    |+ Multiplication table
    |-
    ! scope="col" | &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
    |}
    
    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
    becomes this:
    {| class="wikitable"
    |+ Multiplication table
    |-
    ! scope="col" | &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
    |}
    
    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