Gamepedia Help Wiki
No edit summary
(Redirected page to mw:Help:Tables)
Tag: New redirect
 
Line 1: Line 1:
  +
#REDIRECT[[mw:Help:Tables]]
{{tocright}}
 
{{Note|This page is undergoing heavy modifications. Please stand by|center}}
 
 
Welcome to {{PAGENAME}}! If you are new to Wikis, please read our section [[Basic tables]] first, before proceeding. This page covers information concerning the advanced use of tables. Most of the examples below will be using the "wikitable" class for better visibility of individual table elements.
 
 
<div style="display: inline-block; max-width: 49%;">
 
<div style="font-weight: bold; text-align: center;">You type</div>
 
 
<pre style="overflow-x: auto;">
 
{| class="wikitable"
 
|+ Table caption
 
|-
 
! Header 1
 
! Header 2
 
! Header 3
 
|-
 
| Cell 1, Row 1
 
| Cell 2, Row 1
 
| Cell 3, Row 1
 
|-
 
| Cell 1, Row 2
 
| Cell 2, Row 2
 
| Cell 3, Row 2
 
|}
 
</pre>
 
</div>
 
<div style="display: inline-block; margin-left: 10px; max-width: 49%; vertical-align: top;">
 
<div style="font-weight: bold; text-align: center;">You get</div>
 
<br>
 
{| class="wikitable"
 
|+ Table caption
 
|-
 
! Header 1
 
! Header 2
 
! Header 3
 
|-
 
| Cell 1, Row 1
 
| Cell 2, Row 1
 
| Cell 3, Row 1
 
|-
 
| Cell 1, Row 2
 
| Cell 2, Row 2
 
| Cell 3, Row 2
 
|}
 
</div>
 
 
 
== Table headers ==
 
Table headers can be created by using "<code>!</code>" (exclamation mark) instead of "<code>|</code>" (pipe symbol). Headers usually show up bold and centered by default.
 
 
{{Note| When using attributes as in the heading 'Item' a vertical bar <nowiki>|</nowiki> is used for separation.<br>Not an exclamation character '!'.|center}}
 
<br>
 
<hr>
 
{| width="100%"
 
! style="width: 50%;"|You type
 
! style="width: 50%;"|You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{|
 
! align="left" width="45%" | Left-aligned header
 
! width="45%" | Regular header
 
! Cost
 
|-
 
|Monitor
 
|10
 
|7.00
 
|-
 
|Mouse
 
|4
 
|3.00
 
|-
 
|Gamepad
 
|1
 
|5.00
 
|-
 
! Total (header)
 
|
 
|15.00
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| align="center"
 
! align="left" width="45%" | Left-aligned header
 
! width="45%" | Regular header
 
! Cost
 
|-
 
|Monitor
 
|10
 
|7.00
 
|-
 
|Mouse
 
|4
 
|3.00
 
|-
 
|Gamepad
 
|1
 
|5.00
 
|-
 
! Total (header)
 
|
 
|15.00
 
|}
 
|}
 
 
==Caption==
 
A '''table caption''' can be added to the top of any table as follows.
 
 
{| width="100%"
 
! style="width: 50%;"|You type
 
! style="width: 50%;"|You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{|
 
|+Just gamer things
 
|-
 
|Monitor
 
|Mouse
 
|-
 
|Gamepad
 
|Keyboard
 
|-
 
|Mainboard
 
|Video card
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| align="center"
 
|+Just gamer things
 
|-
 
|Monitor
 
|Mouse
 
|-
 
|Gamepad
 
|Keyboard
 
|-
 
|Mainboard
 
|Video card
 
|}
 
|}
 
 
==class="wikitable"==
 
Basic styling can be achieved by adding class="wikitable".
 
 
{| width="100%"
 
! style="width: 50%;"|You type
 
! style="width: 50%;"|You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{| class="wikitable"
 
|+Just gamer things
 
|-
 
|Monitor
 
|Mouse
 
|-
 
|Gamepad
 
|Keyboard
 
|-
 
|Mainboard
 
|Video card
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| align="center" class="wikitable"
 
|+Just gamer things
 
|-
 
|Monitor
 
|Mouse
 
|-
 
|Gamepad
 
|Keyboard
 
|-
 
|Mainboard
 
|Video card
 
|}
 
|}
 
 
== HTML attributes ==
 
You can add HTML attributes to tables. For the authoritative source on these, see [http://www.w3.org/TR/REC-html40/struct/tables.html the W3C's HTML 4.01 Specification page on tables].
 
 
=== Attributes on tables ===
 
Placing attributes after the table start tag (<code>{|</code>) applies attributes to the entire table.
 
 
{| width="100%"
 
! style="width: 50%;"| You type
 
! style="width: 50%;"| You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{| class="wikitable" style="text-align: center; color: green;"
 
|Monitor
 
|Mouse
 
|12,333.00
 
|-
 
|Gamepad
 
|Keyboard
 
|500.00
 
|-
 
|Mainboard
 
|Video card
 
|1.00
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| class="wikitable" align="center" style="text-align: center; color: green;"
 
|Monitor
 
|Mouse
 
|12,333.00
 
|-
 
|Gamepad
 
|Keyboard
 
|500.00
 
|-
 
|Mainboard
 
|Video card
 
|1.00
 
|}
 
|}
 
 
<center>{{Note|Usually, tables on Gamepedia are already styled with css, so it could happen,<br>that your style settings in a table won't show up because of that!<br>In doubt, please contact an admin.}}</center>
 
 
=== Attributes on cells ===
 
You can put attributes on individual '''cells'''. For example, numbers may look better aligned right.
 
 
{| width="100%"
 
! style="width: 50%;"| You type
 
! style="width: 50%;"| You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{| class="wikitable"
 
| Monitor
 
| Mouse
 
| align="right"| 12,333.00
 
|-
 
| Gamepad
 
| Keyboard
 
| align="right"| 500.00
 
|-
 
| Mainboard
 
| Video card
 
| align="right"| 1.00
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| class="wikitable" align="center"
 
| Monitor
 
| Mouse
 
| align="right"| 12,333.00
 
|-
 
| Gamepad
 
| Keyboard
 
| align="right"| 500.00
 
|-
 
| Mainboard
 
| Video card
 
| align="right"| 1.00
 
|}
 
|}
 
 
You can also use '''cell''' attributes when you are listing multiple '''cells''' on a single line. Note that the '''cells''' are separated by <code>||</code>, and within each '''cell''' the attribute(s) and value are separated by <code>|</code>.
 
 
{| width="100%"
 
! style="width: 50%;"| You type
 
! style="width: 50%;"| You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{| class="wikitable"
 
| Monitor || Mouse || align="right" | 12,333.00
 
|-
 
| Gamepad || Keyboard || align="right" | 500.00
 
|-
 
| Mainboard || Video card || align="right" | 1.00
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| class="wikitable" align="center"
 
| Monitor || Mouse || align="right" | 12,333.00
 
|-
 
| Gamepad || Keyboard || align="right" | 500.00
 
|-
 
| Mainboard || Video card || align="right" | 1.00
 
|}
 
|}
 
 
===Attributes on rows===
 
You can put attributes on individual '''rows''', too.
 
 
{| width="100%"
 
! style="width: 50%;"|You type
 
! style="width: 50%;"|You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{| class="wikitable"
 
| Monitor
 
| Mouse
 
| align="right"| 12,333.00
 
|-
 
| Gamepad
 
| Keyboard
 
| align="right"| 500.00
 
|- style="font-style: italic; color: green;"
 
| Mainboard
 
| Video card
 
| align="right"| 1.00
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| class="wikitable" align="center"
 
| Monitor
 
| Mouse
 
| align="right"| 12,333.00
 
|-
 
| Gamepad
 
| Keyboard
 
| align="right"| 500.00
 
|- style="font-style: italic; color: green;"
 
| Mainboard
 
| Video card
 
| align="right"| 1.00
 
|}
 
|}
 
 
====Simple one-pixel table border====
 
The default table formatting uses the "border-collapse: separate" model, which adds table cell spacing (which also separates the table outer border from its content cells). Even with a zero cellspacing, the borders of consecutive cells (and of the overall table container) will add up, so to get a one-pixel separation between cells, you need to selectively remove one or more of the four borders of cells.
 
 
Such tables may be formatted more simply, using the "border-collapse: collapse" CSS property; in this table formatting model, the cellspacing attribute (or the CSS "border-spacing:" property) and the table's "padding:" CSS property are ignored and only the larger border of adjacent inner cells (or the table border for outer cells) will be used.
 
 
An example of the above for one-pixel table border, using each model (without need for external extensions):
 
 
{| width=100%
 
|-
 
! You type
 
! You get
 
|-
 
| width=50% style="padding: 5px;" |
 
<pre style="font-size: 90%">
 
{| style="border-collapse: separate;
 
border-spacing: 0;
 
border: 1px solid #000;
 
padding: 0"
 
|-
 
| style="border-style: solid; border-width: 0 1px 1px 0"|
 
Monitor
 
| style="border-style: solid; border-width: 0 0 1px 0"|
 
Mouse
 
|-
 
| style="border-style: solid; border-width: 0 1px 0 0"|
 
Gamepad
 
| style="border-style: solid; border-width: 0"|
 
Keyboard
 
|}
 
</pre>
 
| width=50% style="padding: 20px;"|
 
{| style="border-collapse: separate; border-spacing: 0; border: 1px solid #000; padding: 0"
 
|-
 
| style="border-style: solid; border-width: 0 1px 1px 0"| Monitor
 
| style="border-style: solid; border-width: 0 0 1px 0"| Mouse
 
|-
 
| style="border-style: solid; border-width: 0 1px 0 0"| Gamepad
 
| style="border-style: solid; border-width: 0"| Keyboard
 
|}
 
|-
 
| style="padding: 5px;"|
 
<pre style="font-size: 90%">
 
{| style="border-collapse: collapse; border: 1px solid #000"
 
|-
 
| style="border-style: solid; border-width: 1px"|
 
Monitor
 
| style="border-style: solid; border-width: 1px"|
 
Mouse
 
|-
 
| style="border-style: solid; border-width: 1px"|
 
Gamepad
 
| style="border-style: solid; border-width: 1px"|
 
Keyboard
 
|}
 
</pre>
 
| style="padding: 20px;"|
 
{| style="border-collapse: collapse; border: 1px solid #000"
 
|-
 
| style="border-style: solid; border-width: 1px"| Monitor
 
| style="border-style: solid; border-width: 1px"| Mouse
 
|-
 
| style="border-style: solid; border-width: 1px"| Gamepad
 
| style="border-style: solid; border-width: 1px"| Keyboard
 
|}
 
|}
 
{{Note
 
| <ul style{{=}}"text-align: left;">
 
<li>When using the "border-width:" CSS shortcut property, the order of the four space-separated specified values is: top, right, bottom, left. From the example above:
 
::<code>"border-width: 0 1px 0 0"</code>
 
</li>
 
<li>When there are only 2 values, the first value for specifies both the top and bottom border widths and the second value specifies both the right and left border widths.
 
</li>
 
<li>The '''HTML attributes''' (such as "width{{=}}", "border{{=}}", "cellspacing{{=}}", "cellpadding{{=}}") do '''not''' need any length unit (the pixel unit is assumed). The '''CSS''' style properties (which override the HTML attributes) '''require''' an explicit length unit (if the value is not 0) such as "px" for the pixel.
 
</li>
 
</ul>
 
}}
 
 
===HTML colspan and rowspan===
 
 
You can use HTML '''colspan''' and '''rowspan''' attributes on cells for advanced layout.
 
 
{| width="100%"
 
! style="width: 50%;"|You type
 
! style="width: 50%;"|You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{| class="wikitable"
 
!colspan="6"|Shopping List
 
|-
 
|rowspan="2"|Computer parts
 
|Mainboard
 
|Video card
 
|Power supply
 
|colspan="2"|DVD burner
 
|-
 
|Hardrive
 
|colspan="2"|Memory
 
|CPU
 
|Case fan
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| class="wikitable" align="center"
 
!colspan="6"|Shopping List
 
|-
 
|rowspan="2"|Computer parts
 
|Mainboard
 
|Video card
 
|Power supply
 
|colspan="2"|DVD burner
 
|-
 
|Hardrive
 
|colspan="2"|Memory
 
|CPU
 
|Case fan
 
|}
 
|}
 
 
===With HTML attributes and CSS styles===
 
[[mediawikiwiki:Manual:CSS|CSS]] style attributes can be added with or without other HTML attributes.
 
 
{| width="100%"
 
! style="width: 50%;"|You type
 
! style="width: 50%;"|You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{| class="wikitable" style="color:green; background-color:#ffffcc;" cellpadding="10"
 
|Monitor
 
|Mouse
 
|-
 
|Mainboard
 
|Gamepad
 
|-
 
|Keyboard
 
|Video card
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| class="wikitable" style="color:green; background-color:#ffffcc;" cellpadding="10"
 
|Monitor
 
|Mouse
 
|-
 
|Mainboard
 
|Gamepad
 
|-
 
|Keyboard
 
|Video card
 
|}
 
|}
 
 
====Attributes====
 
'''Attributes''' can be added to the caption and headers as follows.
 
 
{| width="100%"
 
! style="width: 50%;"|You type
 
! style="width: 50%;"|You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{| class="wikitable"
 
|+ align="bottom" style="color:#e76700;"|''Computer parts''
 
|-
 
|Monitor
 
|Mouse
 
|-
 
|Gamepad
 
|Keyboard
 
|-
 
|Mainboard
 
|Video card
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| class="wikitable"
 
|+ align="bottom" style="color:#e76700;" |''Computer parts''
 
|-
 
|Monitor
 
|Mouse
 
|-
 
|Gamepad
 
|Keyboard
 
|-
 
|Mainboard
 
|Video card
 
|}
 
|}
 
 
====Column width====
 
'''Column width''' can be added as follows.
 
 
You type:
 
<pre>
 
{| style="color: black; background-color: #D5E861;" width="85%"
 
| colspan="2" | This column width is 85% of the screen width (and has a background color)
 
|-
 
| style="width: 30%; background-color: white;"|
 
'''This column is 30% counted from 85% of the screen width'''
 
| style="width: 70%; background-color: orange;"|
 
'''This column is 70% counted from 85% of the screen width (and has a background color)'''
 
|}
 
</pre>
 
 
You get:
 
{| style="color: black; background-color: #D5E861;" width="85%"
 
| colspan="2" | This column width is 85% of the screen width (and has a background color)
 
|-
 
| style="width: 30%; background-color: white;"| '''This column is 30% counted from 85% of the screen width'''
 
| style="width: 70%; background-color: orange;"| '''This column is 70% counted from 85% of the screen width (and has a background color)'''
 
|}
 
 
===Accessibility of table header cells===
 
Table header cells do not explicitly specify which table data cells they apply to (those on their right on the same row, or those below them on the same column). When the table is rendered in a visual 2D environment, this is usually easy to infer.
 
 
However when tables are rendered on non-visual media, you can help the browser to determine which table header cell applies to the description of any selected cell (in order to repeat its content in some accessibility helper) using a scope="row" or scope="col" attribute on table header cells. In most cases with simple tables, you'll use scope="col" on all header cells of the first row, and scope="row" on the first cell of the following rows:
 
 
{| width="100%"
 
! style="width: 50%;"|You type
 
! style="width: 50%;"|You get
 
|-
 
| style="padding: 5px;"|
 
<pre>
 
{| class="wikitable"
 
|-
 
! scope="col"| Item
 
! scope="col"| Quantity
 
! scope="col"| Price
 
|-
 
! scope="row"| DVDs
 
| 6
 
| $3
 
|-
 
! scope="row"| Monitor
 
| 1
 
| $1500
 
|-
 
! scope="row" colspan="2"| Total
 
| $1503
 
|}
 
</pre>
 
| style="padding: 5px;"|
 
{| class="wikitable" align="center"
 
|-
 
! scope="col"| Item
 
! scope="col"| Quantity
 
! scope="col"| Price
 
|-
 
! scope="row"| DVDs
 
| 6
 
| $3
 
|-
 
! scope="row"| Monitor
 
| 1
 
| $1500
 
|-
 
! scope="row" colspan="2"| Total
 
| $1503
 
|}
 
|}
 
 
==Caveats==
 
 
===Negative numbers===
 
If you start a cell on a new line with a negative number with a minus sign (or a parameter that evaluates to a negative number), your table can get broken, because the characters <code>|-</code> will be parsed as the wiki markup for table row, not table cell. To avoid this, insert a space before the value (<code>| -6</code>) or use in-line cell markup (<code>|| -6</code>).
 
 
===CSS vs attributes===
 
While CSS is the preferred method for styling tables, borders specified through CSS rather than the border attribute can render incorrectly in a small subset of text browsers.
 
 
===Common attributes for columns, column groups and row groups===
 
The MediaWiki syntax for tables currently offers no support for specifying common attributes for columns (with the HTML element <code>&lt;col /&gt;</code>), column groups (HTML element <code>&lt;colgroup&gt;...&lt;/colgroup&gt;</code>) and row groups (HTML elements <code>&lt;thead&gt;...&lt;/thead&gt;</code>, <code>&lt;tbody&gt;...&lt;/tbody&gt;</code> and <code>&lt;tfoot&gt;...&lt;/tfoot&gt;</code>). Those standard HTML elements are not accepted even in their HTML or XHTML syntax.
 
 
All the rows and cells (header or data) of the table are rendered within a single implicit row group (HTML element <code>&lt;tbody&gt;...&lt;/tbody&gt;</code>) without any attributes or styles.
 
 
==See also==
 
* [[Help:Sorting]]
 
 
[[Category:Advanced editing]]
 

Latest revision as of 20:10, 2 August 2019

Redirect to: