Help:Tables
Tables and templates are often cited as the most daunting thing about editing the wiki, but they need not be feared. Like anything else, if you do end up breaking something, another editor can always help out.
General syntax[edit]
The following symbols can be used to construct a table:
{| {{STDT}}
= The beginning of a table, always on a new line. The STDT bit is a template (Template:STDT) used to apply a consistent style to all wiki tables.|-
= When used at the beginning of a line, this symbolises a new table row. Optional for the first row.|
= When used at the beginning of a line, this symbolises a new table cell||
= When a new cell is required (other than at the beginning of a line).!
and!!
= Same as the pipes above for new cells, but symbolises a heading cell (usually bold).- Use a new line with one exclamation mark if you wish to have a heading cell following a plain cell.
|}
= The end of a table, always on a new line.
Example 1[edit]
A simple example with six cells spread across two columns and three rows
{| {{STDT}} |- ! Header cell A (column 1, row 1) ! Header cell B (column 2, row 1) |- | Plain cell C (column 1, row 2) | Plain cell D (column 2, row 2) |- | Plain cell E (column 1, row 3) | Plain cell F (column 2, row 3) |}
Header cell A (column 1, row 1) | Header cell B (column 2, row 1) |
---|---|
Plain cell C (column 1, row 2) | Plain cell D (column 2, row 2) |
Plain cell E (column 1, row 3) | Plain cell F (column 2, row 3) |
Example 2[edit]
Same as above but using double-pipes instead of newlines for the second column:
{| {{STDT}} |- ! Header cell A (column 1, row 1) !! Header cell B (column 2, row 1) |- | Plain cell C (column 1, row 2) || Plain cell D (column 2, row 2) |- | Plain cell E (column 1, row 3) || Plain cell F (column 2, row 3) |}
Header cell A (column 1, row 1) | Header cell B (column 2, row 1) |
---|---|
Plain cell C (column 1, row 2) | Plain cell D (column 2, row 2) |
Plain cell E (column 1, row 3) | Plain cell F (column 2, row 3) |
Example 3[edit]
Often tables will contain a high level heading for which merged cells are appropriate. Cells are merged by preceding their content with colspan="2" |
or rowspan="2" |
, with the 2 replaced by the number of cells to be merged.
The excessive spaces in the example below are purely cosmetic and have no effect on the output appearance of the table. Note that merging rows can quickly make tables complex to edit and thus should be avoided to encourage any level of editor to be able to edit the page, the following example however contains both a merged column and a merged row for illustration. Where possible, think about how to best display the information prior to creating difficult to interpret tables.
{| {{STDT}} |- ! Header cell A (column 1, row 1) !! colspan="2" | Header cell B (columns 2 and 3, row 1) |- | rowspan="2" | Plain cell C (column 1, rows 2 and 3) || Plain cell D (column 2, row 2) || Plain cell E (column 2, row 2) |- | Plain cell F (column 2, row 3) || Plain cell G (column 2, row 3) |}
Header cell A (column 1, row 1) | Header cell B (columns 2 and 3, row 1) | |
---|---|---|
Plain cell C (column 1, rows 2 and 3) | Plain cell D (column 2, row 2) | Plain cell E (column 2, row 2) |
Plain cell F (column 2, row 3) | Plain cell G (column 2, row 3) |
Armed with the above information you can now tackle any table on the wiki. However the remaining examples contain some useful additional syntax.
Table positioning[edit]
Tables with the STDT template at the top become inline-block elements (same as applying the CSS property "display:inline-block"), which allows placing several small tables next to each other by writing them immediately after each other:
{| {{STDT}} ! colspan="2" | [[Bronze Ingot]] |- | 10 || [[Copper Ore]] |- | 1 || [[Lump of Tin]] |} {| {{STDT}} ! colspan="2" | [[Steel Ingot]] |- | 3 || [[Iron Ore]] |- | 1 || [[Lump of Coal]] |}
Bronze Ingot | |
---|---|
10 | Copper Ore |
1 | Lump of Tin |
Steel Ingot | |
---|---|
3 | Iron Ore |
1 | Lump of Coal |
Table width[edit]
Sometimes tables should have defined widths. In this case, you can add style="width:Xpx;"
to the table formatting. This can be done in the table header (so that it affects the whole table), or before a table cell (so it affects just that column). Widths can also be specified in % (percent), in which case a max-width should also be set so that tables don't stretch too much in larger screens. Note that defining a max-width also requires you to define the width of each cell for one of the rows due to quirks of our CSS.
{| {{STDT}} ! colspan="2" | [[Bronze Ingot]] |- | 10 || [[Copper Ore]] |- | 1 || [[Lump of Tin]] |} {| {{STDT}} ! colspan="2" | [[Steel Ingot]] |- | style="width:400px;" | 3 || style="width:600px;" | [[Iron Ore]] |- | 1 || [[Lump of Coal]] |}
Bronze Ingot | |
---|---|
10 | Copper Ore |
1 | Lump of Tin |
Steel Ingot | |
---|---|
3 | Iron Ore |
1 | Lump of Coal |
Multiple headings[edit]
The first row is always a heading row with a unique style (it is taller and has a background gradient in many cases). If you need another row with this design, simply add class="heading"
to the row above where you want the style to appear. For example, the following code
{| {{STDT}} ! DE |- | Abaddon's Mouth |- | Dasha |- | Drakkar Lake |- class="heading" ! FR |- | Arborstone |- | Augury Rock |- | Echovald Forest |- class="heading" ! General |- | Aurora Glade |- | Bjora Marches |- | Blacktide |}
will result in a table like this:
DE |
---|
Abaddon's Mouth |
Dasha |
Drakkar Lake |
FR |
Arborstone |
Augury Rock |
Echovald Forest |
General |
Aurora Glade |
Bjora Marches |
Blacktide |
Table colors[edit]
Tables may have different color depending on context. This can be done by adding an unnamed parameter to STDT template, like this:
{| {{STDT|recipe}} ! colspan="2" | [[Bronze Ingot]] |- | 10 || [[Copper Ore]] |- | 1 || [[Lump of Tin]] |}
Bronze Ingot | |
---|---|
10 | Copper Ore |
1 | Lump of Tin |
Note that applying the class to the table affects both header and plain cells. For the complete list of available color options, see Template:STDT#Color examples
Applying different colors to a given row[edit]
When a table uses several colors, define colors within each row by adding class="XXX"
to it, like this:
{| {{STDT|skills}} ! Profession ! Shout ! Description |- class="guardian" ! rowspan="3" | [[Guardian]] | "Hold the Line!" | Grant protection and regeneration to allies. |- class="guardian" | "Retreat!" | Grant aegis and swiftness to up to five nearby allies.} |- class="guardian line" | "Stand Your Ground!" | Grants stability and retaliation to yourself and allies. |- class="warrior" ! rowspan="4" | [[Warrior]] | "Fear Me!" | Induce fear in your foes. |- class="warrior" | "For Great Justice!" | Grant fury and might to yourself and allies. |}
Profession | Shout | Description |
---|---|---|
Guardian | "Hold the Line!" | Grant protection and regeneration to allies. |
"Retreat!" | Grant aegis and swiftness to up to five nearby allies. | |
"Stand Your Ground!" | Grants stability and retaliation to yourself and allies. | |
Warrior | "Fear Me!" | Induce fear in your foes. |
"For Great Justice!" | Grant fury and might to yourself and allies. |
Other table classes[edit]
Sortable tables[edit]
The "sortable" class allows the table contents to be sorted (either alphabetically, numerically or by date) when the first row header cells (with the up/down arrows) are clicked on. Holding shift whilst clicking on a header allows you to sort by more than one column.
{| {{STDT|mesmer sortable}} |- ! Skill name !! Recharge |- ! [[Distortion]] | 50 |- ! [[Cry of Frustration]] | 30 |- ! [[Mind Wrack]] | 12 |- ! [[Diversion]] | 30 |}
Skill name | Recharge |
---|---|
Distortion | 50 |
Cry of Frustration | 30 |
Mind Wrack | 12 |
Diversion | 30 |
Alignment[edit]
By default, text in tables is aligned to the left horizontally, and to the middle vertically. In heading cells, text is centered horizontally instead. Sometimes, text should be aligned in a different way than the default, e.g. for a table containing mostly numbers, you might want to align the content to the right.
{| {{STDT|item align-right}} ! Item name !! Collection !! Buy price in coin !! Sell price in coin |- | [[Cooguloosh]] || N/A || {{coin|270000}} || {{coin|400400}} |- | [[Titans' Vengeance]] || N/A || {{coin|1000050}} || {{coin|1570800}} |- | [[Mystic Artifact]] || Treasure Hunter || {{coin|529699}} || {{coin|341246}} |}
Item name | Collection | Buy price in coin | Sell price in coin |
---|---|---|---|
Cooguloosh | N/A | 27 | 40 4 |
Titans' Vengeance | N/A | 100 50 | 157 8 |
Mystic Artifact | Treasure Hunter | 52 96 99 | 34 12 46 |
Align-right is used in the above example, but the following horizontal alignments are also available: align-left
, align-center
. Additionally three vertical alignments are available: align-top
, align-middle
and align-bottom
.
These table classes can also be combined with cell-specific style overrides:
{| {{STDT|item align-right}} ! Item name !! Collection !! Buy price in coin !! Sell price in coin |- | style="text-align:left;" | [[Cooguloosh]] || N/A || {{coin|270000}} || {{coin|400400}} |- | style="text-align:left;" | [[Titans' Vengeance]] || N/A || {{coin|1000050}} || {{coin|1570800}} |- | style="text-align:left;" | [[Mystic Artifact]] || Treasure Hunter || {{coin|529699}} || {{coin|341246}} |}
Item name | Collection | Buy price in coin | Sell price in coin |
---|---|---|---|
Cooguloosh | N/A | 27 | 40 4 |
Titans' Vengeance | N/A | 100 50 | 157 8 |
Mystic Artifact | Treasure Hunter | 52 96 99 | 34 12 46 |
Cell and row borders[edit]
To add borders to cells or rows the following classes are available:
line
andline-bottom
adds a line beneath the current row or cellline-top
adds a line above the current row or cellline-left
orline-right
adds a line to the left/right of the current cell
Colspanned and rowspanned cells automatically show all of their borders.
Note[edit]
- Tables can be used within templates and functions, however any occurence of a
|
pipe needs to be replaced with the pipe template{{!}}
.
See also[edit]
- Wikipedia's Help:Table page
- Wikipedia's Help:Sorting page, for all details about sortable tables.
- Meta-Wiki's Help:Table page
- MediaWiki talk:CollapsibleTables.js - For tables that can be collapsed via show/hide buttons to show or hide the content apart from the table headers.
- Guild Wars 2 Wiki:Color schemes