Help:Table
Imported Wiki Text |
---|
Some or all of the text of the Help:Table page on Looney Pyramid Games Wiki has been imported from Help:Table on meta.wikimedia.org. Some text, images and links may not yet (or ever) be correct for Looney Pyramid Games Wiki (but feel free to improve the page). If necessary, you may be able to get more information on those images and links at the source page site. http://meta.wikimedia.org/wiki/Help:Table |
Pipe syntax[edit source]
Please note that the use of HTML is no longer necessary or desired. This has been replaced by wikicode pipe syntax.
- Easily convert HTML tables to Wikimarkup tables with Magnus Manske's conversion tool.
Special wikitext code can be used to create a table, as follows.
- The entire table begins with a line
{|
optional table parameters and ends with the line|}
. - A caption is a succinct way to describe the table; it is optional, and included with a line
|+
caption after{|
. - The code for a table row consists of the line
|-
, and, starting on a new line, the codes for the cells in the row, separated by newline or "|" - Table data are the codes for the cells; cell code is of the form | value or | cell parameters | value
- a row of column headings is identified by using "!" instead of "|", except for the separator between a cell parameter and a value; the difference with a normal row depends on the browser, column headings are often rendered in a bold font.
- the first cell of a row is identified as row heading by starting the line with "!" instead of "|", and starting subsequent data cells on a new line.
The table parameters and cell parameters are the same as in HTML [1].
Each row must have the same number of cells as the other rows, so that the number of columns in the table remains consistent (unless there are cells which span several columns or rows, but this is not discussed here). For empty cells, use the non-breaking space
as content to ensure that the cells are displayed.
Examples[edit source]
Multiplication table[edit source]
Source code[edit source]
{| border="1" cellpadding="2" |+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 |}
Appearance[edit source]
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
Mélange[edit source]
Here's a more advanced example, showing some more options available for making up tables. You can play with these settings in your own table to see what effect they have. Not all of these techniques may be appropriate in all cases; just because you can add colored backgrounds, for example, doesn't mean it's always a good idea. Try to keep the markup in your tables relatively simple -- remember, other people are going to be editing the article too! This example should give you an idea of what is possible, though.
Source code[edit source]
{| 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 Wikipedia logos |} |}
Appearance[edit source]
An example table First header Second header upper left right side
lower left lower middle
A table in a table Two Wikipedia logos
Simple example[edit source]
{| | Cell 1, row 1 | Cell 2, row 1 |- | Cell 1, row 2 | Cell 2, row 2 |}
generates
Cell 1, row 1 | Cell 2, row 1 |
Cell 1, row 2 | Cell 2, row 2 |
Advanced example[edit source]
{| align=right border=1 | Cell 1, row 1 |rowspan=2| Cell 2, row 1 (and 2) | Cell 3, row 1 |- | Cell 1, row 2 | Cell 3, row 2 |}
Cell 1, row 1 | Cell 2, row 1 (and 2) | Cell 3, row 1 |
Cell 1, row 2 | Cell 3, row 2 |
Note the floating table to the right.
Nested table[edit source]
{| border=1 | α | {| bgcolor=#ABCDEF border=2 |nested |- |table |} |the original table again |}
gives a nested table
α |
|
the original table again |
Nested tables have to start on a new line.
Other table syntax[edit source]
Other types of table syntax that MediaWiki supports:
- XHTML
- HTML and wiki <td> syntax
All three are supported by MediaWiki and create (currently) valid HTML output, but the pipe syntax is the simplest, except perhaps for people who are already familiar with HTML. Also, HTML and wiki <td> syntax will not necessarily remain browser-supported in the upcoming future, especially on handheld internet-accessible devices.
See also HTML element#Tables. Note however that the thead
, tbody
, tfoot
, and colgroup
elements are currently not supported in MediaWiki.
Comparison[edit source]
XHTML | HTML & Wiki-td | Wiki-pipe | |||||||
---|---|---|---|---|---|---|---|---|---|
Table | <table></table> | <table></table> | {| params |} | ||||||
Caption | <caption></caption> | <caption></caption> | |+ caption | ||||||
Row | <tr></tr> | <tr> | |- params | ||||||
Data cell |
<td>cell1</td> |
<td>cell1 |
| cell1 | cell2 | ||||||
Data cell | <td>cell1</td> <td>cell2</td> <td>cell3</td> | <td>cell1 <td>cell2 <td>cell3 | |cell1||cell2||cell3 | ||||||
Header cell | <th></th> | <th> | ! heading | ||||||
Sample table |
| ||||||||
<table> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>3</td> <td>4</td> </tr> </table> | <table> <tr> <td> 1 <td> 2 <tr> <td> 3 <td> 4 </table> | {| | 1 || 2 |- | 3 || 4 |} | |||||||
Sample table |
| ||||||||
<table> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> </tr> </table> | <table> <tr> <td> 1 <td> 2 <tr> <td> 3 <td> 4 <tr> <td> 5 <td> 6 </table> | {| | 1 || 2 |- | 3 || 4 |- | 5 || 6 |} | |||||||
Pros |
Can be previewed/debugged with any XHTML editor Can be formatted for easier reading Well-known |
Can be previewed/debugged with any HTML editor Can be formatted for easier reading Well-known Takes less space than XHTML |
Easy to write Easy to read Takes little space | ||||||
Cons |
Tedious Takes a lot of space Difficult to read quickly |
Confusing, especially for people with little HTML experience Poorly formed Poorly delimited Generally odd looking May not have browser support in future |
Unfamiliar syntax Rigid structure Cannot be indented | ||||||
XHTML | HTML & Wiki-td | Wiki-pipe |
Pipe syntax in terms of the HTML produced[edit source]
The pipe syntax, developed by Magnus Manske, substitutes pipes (|) for HTML. There is an on-line script which converts html tables to pipe syntax tables.
The pipes must start at the beginning of a new line, except when separating parameters from content or when using ||
to separate cells on a single line. The parameters are optional.
Tables[edit source]
A table is defined by {| ''params'' |} which equals <table ''params''>Insert non-formatted text here </table>
- Careful: You must include the space between
{|
andparams
, or the first parameter gets ignored.
Rows[edit source]
<tr> tags will be generated automatically for the first row. To start a new row, use
|-
which results in
<tr>
Parameters can be added like this:
|- params
which results in
<tr params>
Note:
- <tr> tags will be automatically opened at the first <td> equivalent
- <tr> tags will be automatically closed at <tr> and </table> equivalents
Cells[edit source]
Cells are generated either like this:
|cell1 |cell2 |cell3
or like this:
|cell1||cell2||cell3
which both equal
<td>cell1</td><td>cell2</td><td>cell3</td>
so "||" equals "newline" + "|"
Parameters in cells can be used like this:
|params|cell1||params|cell2||params|cell3
which will result in
<td params>
Headers[edit source]
Functions the same way as TD, except "!" is used instead of the opening "|". "!!" can be used instead of "||". Parameters still use "|", though! Example:
!params|cell1
Captions[edit source]
A <caption> tag is created by
|+ Caption
which generates
<caption>Caption</caption>
You can also use parameters:
|+ params|Caption
which will generate
<caption params>Caption</caption>
Text next to a table[edit source]
(To see demonstrated effects, you may have to increase or decrease the fontsize setting of the browser; also you can vary the width of the browser window.)
You can use align=right, text after the table code appears to the left of the table. However, do not put preformatted text, it may overlap the table because it does not wrap.
× | 1 | 2 | 3 |
---|---|---|---|
1 | 1 | 2 | 3 |
2 | 2 | 4 | 6 |
3 | 3 | 6 | 9 |
4 | 4 | 8 | 12 |
5 | 5 | 10 | 15 |
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
To prevent this, use <br style="clear:both;">:
× | 1 | 2 | 3 |
---|---|---|---|
1 | 1 | 2 | 3 |
2 | 2 | 4 | 6 |
3 | 3 | 6 | 9 |
4 | 4 | 8 | 12 |
5 | 5 | 10 | 15 |
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
You can use align=left, text after the table code appears to the left of the table.
× | 1 | 2 | 3 |
---|---|---|---|
1 | 1 | 2 | 3 |
2 | 2 | 4 | 6 |
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
Space around a table, image, or text[edit source]
To create space around a table, image, or text, create a 1×1 table around it, with cellpadding:
|
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
text in box |
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
Setting your column widths[edit source]
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.
{| border="1" cellpadding="2" !width="50"|Name !width="225"|Effect !width="225"|Games Found In |- |Pokeball |Regular Pokeball |All Versions |- |Great Ball |Better than a Pokeball |All Versions |}
Name Effect Games Found In Pokeball Regular Pokeball All Versions Great Ball Better than a Pokeball All Versions
Setting parameters[edit source]
At the start of a cell, add your parameter followed by a single pipe. For example width=300px| will set that cell to a width of 300 pixels. To set more than one parameter, leave a space between each one.
Wikipedia code[edit source]
{| |- | bgcolor=red|cell1 || width=300px bgcolor=blue|cell2 || bgcolor=green|cell3 |}
What it looks like in your browser[edit source]
cell1 cell2 cell3
Decimal point alignment[edit source]
A method to get columns of numbers aligned at the decimal point is as follows:
<blockquote> {| cellpadding=0 cellspacing=0 |align=right| 432 || . || 1 |- |align=right| 43 || . || 21 |- |align=right| 4 || . || 321 |} </blockquote>
gives
432 . 1 43 . 21 4 . 321
In simple cases one can dispense with the table feature and simply start the lines with a space, and put spaces to position the numbers:
432.1 43.21 4.321
Style templates[edit source]
Some helpful templates have been written to make table styles easier. Instead of remembering table parameters, you just include the style template after the {|
. This helps keep table formatting consistent, and can allow a single change to the template to fix a problem or enhance the look of all tables that use it. This:
× | 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:
× | 1 | 2 | 3 |
---|---|---|---|
1 | 1 | 2 | 3 |
2 | 2 | 4 | 6 |
3 | 3 | 6 | 9 |
4 | 4 | 8 | 12 |
5 | 5 | 10 | 15 |
simply by replacing the border="1" cellpadding="2"
section with {{prettytable}}
, because (on this wiki) Template:Prettytable contains the following style rules:
border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;".
.
All of these templates should be organized/listed in a single place, like here.
See also[edit source]
External links[edit source]
- HTML tables to wiki converter at cnic.org
- csv2wp - converts comma-separated values (CSV) format to pipe syntax. You may use this to import tables from Excel etc. (more information)
- HTML tables to wiki converter at wackyboy.com
- HTML tables to wiki converter at uni-bonn.de
- HTML tables to wiki converter at diberri.dyndns.org
- pywikipediabot (can convert HTML tables to wiki)