Help:Tables: Difference between revisions
m (→Basics: class="wikidata" → class="wikitable") |
(→Templates for comparison tables etc: New section) |
||
Line 119: | Line 119: | ||
|- | |- | ||
| Cell five || Cell six || Cell seven | | Cell five || Cell six || Cell seven | ||
|} | |||
== Templates for comparison tables etc == | |||
For templates with a lot of cells with similar text, for example tables with comparisons of features or compatibility there are three small helpful templates, {{tl|yes}}, {{tl|no}} and {{tl|n/a}}. They can have an optional text instead of the default one if needed. Below is what they look like in use: | |||
{| class="wikitable" | |||
! Template !! Default text !! Template !! With optional text | |||
|- | |||
| <code><nowiki>{{yes}}</nowiki></code> || {{yes}} || <code><nowiki>{{yes|Yep!}}</nowiki></code> || {{yes|Yep!}} | |||
|- | |||
| <code><nowiki>{{no}}</nowiki></code> || {{no}} || <code><nowiki>{{no|Nope!}}</nowiki></code> || {{no|Nope!}} | |||
|- | |||
| <code><nowiki>{{n/a}}</nowiki></code> || {{n/a}} || <code><nowiki>{{n/a|Huh?}}</nowiki></code> || {{n/a|Huh?}} | |||
|} | |} | ||
Revision as of 19:31, 23 November 2013
Tables are a very common way to list items belonging to each other.
Basics
Unless you have experience from a wiki using the MediaWiki markup the tables will probably look a bit different than you first expected. Below is a minimalistic example of a table:
{| class="wikitable" |+ Caption ! Header one !! Header two |- | Cell one || Cell two |}
Table markup
Below is the marks that the tables are build with explained, in a table non the less.
Mark | Purpose | Use is | Comments |
---|---|---|---|
{| |
Start of table | Mandatory | |
|+ |
Caption | Optional | Must be between the start of the table and the first row when used |
! |
Header | Optional | Can be at other places than on top |
!! |
Header | Optional | Used between headers on the same line |
|- |
Row | Mandatory | Optional before the first row |
| |
Table data | Mandatory | |
|| |
Table data | Optional | Used between cells on the same line |
|} |
End of table | Mandatory |
Some important notes
Tables may break very easily, so here are some notes to help prevent that:
- All marks, except
!!
and||
must, except for blank spaces, start a new line. - Some wiki markup, like headers and lists, that must start a new line must be put on a new line below the table data or header marks,
|
or!
. - XHTML attributes, like
class="wikitable"
andstyle="style"
, separated by single spaces can be used after a mark that starts a new line, however:- A vertical stroke,
|
, must separate the XHTML attributes from any content that follows. - After marks that do not hold content,
{|
and|-
, any attributes must not be followed by a vertical stroke,|
.
- A vertical stroke,
- Cells may not contain vertical strokes
|
. Two ways around this is either using {{!}} or using<nowiki>|</nowiki>
.
A few simple examples
Here is a very simple example table:
{| class="wikitable" ! Cell one ! Cell two ! Cell three |- | Cell four | Cell five | Cell six |- | Cell seven | Cell eight | Cell nine |}
Cell one | Cell two | Cell three |
---|---|---|
Cell four | Cell five | Cell six |
Cell seven | Cell eight | Cell nine |
The same table can be had with this slightly more compact markup:
{| class="wikitable" ! Cell one !! Cell two !! Cell three |- | Cell four || Cell five || Cell six |- | Cell seven || Cell eight || Cell nine |}
In above examples an XHTML attribute, class="wikitable"
, was used to define the style of the table. The reason for the lack of a default style is that tables then are very useful for many other things, like infoboxes with data about an aircraft, navboxes that help navigating a subject or the main page layout.
Without the class="wikitable"
attribute the table would have looked like below:
Cell one | Cell two | Cell three |
---|---|---|
Cell four | Cell five | Cell six |
Cell seven | Cell eight | Cell nine |
Spanning rows and columns
Using the attributes rowspan="rows"
and colspan="columns"
one can define cells that span more than one row or column.
Do note that:
- The mark preceding an attribute must, except for blank spaces, start a new line.
- The attributes are separated from the content by a vertical stroke
|
. - Removed cells are not defined as they do not exist any more.
{| class="wikitable" ! colspan="2" | Cell one ! rowspan="2" | Cell two |- ! Cell three !! Cell four |- | Cell five || Cell six || Cell seven |}
Cell one | Cell two | |
---|---|---|
Cell three | Cell four | |
Cell five | Cell six | Cell seven |
Templates for comparison tables etc
For templates with a lot of cells with similar text, for example tables with comparisons of features or compatibility there are three small helpful templates, {{yes}}, {{no}} and {{n/a}}. They can have an optional text instead of the default one if needed. Below is what they look like in use:
Template | Default text | Template | With optional text |
---|---|---|---|
{{yes}} |
Yes | {{yes|Yep!}} |
Yep! |
{{no}} |
No | {{no|Nope!}} |
Nope! |
{{n/a}} |
N/A | {{n/a|Huh?}} |
Huh? |
Sortable tables
Tables can be made sortable by using the attribute class="wikitable sortable"
istead of class="wikitable"
.
{| class="wikitable sortable" ! Cell one !! Cell two !! Cell three |- | Cell four || Cell five || Cell six |- | Cell seven || Cell eight || Cell nine |}
Cell one | Cell two | Cell three |
---|---|---|
Cell four | Cell five | Cell six |
Cell seven | Cell eight | Cell nine |