Help:Tables: Difference between revisions
(Created page with "'''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 proba...") |
(+ Wiki help navbar template) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Wiki help navbar}} | |||
'''Tables''' are a very common way to list items belonging to each other. | '''Tables''' are a very common way to list items belonging to each other. | ||
Line 5: | Line 7: | ||
<pre> | <pre> | ||
{| class=" | {| class="wikitable" | ||
|+ Caption | |+ Caption | ||
! Header one !! Header two | ! Header one !! Header two | ||
Line 119: | Line 121: | ||
|- | |- | ||
| 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 four small helpful templates, {{tl|yes}}, {{tl|no}}, {{tl|partial}} 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>{{partial}}</nowiki></code> || {{partial}} || <code><nowiki>{{partial|Maybe...}}</nowiki></code> || {{partial|Maybe...}} | |||
|- | |||
| <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?}} | |||
|} | |} | ||
== Sortable tables == | == Sortable tables == | ||
Tables can be made sortable by using the attribute <code>class="wikitable sortable"</code> | Tables can be made sortable by using the attribute <code>class="wikitable sortable"</code> instead of <code>class="wikitable"</code>. | ||
Columns can be made non-sortable using the attribute <code>class="unsortable"</code>. | |||
< | <nowiki>{| class="wikitable sortable" | ||
{| class="wikitable sortable" | ! Cell one !! Cell two | ||
! Cell one !! Cell two ! | ! class="unsortable" | Cell three | ||
|- | |- | ||
| Cell four || Cell five || Cell six | | Cell four || Cell five || Cell six | ||
|- | |- | ||
| Cell seven || Cell eight || Cell nine | | Cell seven || Cell eight || Cell nine | ||
|} | |}</nowiki> | ||
</ | |||
{| class="wikitable sortable" | {| class="wikitable sortable" | ||
! Cell one !! Cell two ! | ! Cell one !! Cell two | ||
! class="unsortable" | Cell three | |||
|- | |- | ||
| Cell four || Cell five || Cell six | | Cell four || Cell five || Cell six | ||
Line 143: | Line 162: | ||
== External links == | == External links == | ||
* | * {{mediawiki|MediaWiki}} | ||
** | ** {{mediawiki|Help:Tables}} | ||
** | ** {{mediawiki|Help:Sorting}} | ||
* [http://meta.wikimedia.org/wiki/Meta:About_Meta Wikimedia Meta-Wiki] | * [http://meta.wikimedia.org/wiki/Meta:About_Meta Wikimedia Meta-Wiki] | ||
** [http://meta.wikimedia.org/wiki/Help:Table Meta:Help:Table] | ** [http://meta.wikimedia.org/wiki/Help:Table Meta:Help:Table] |
Latest revision as of 11:49, 3 June 2018
Wiki help |
---|
Reading |
Editing |
Advanced editing |
Writing about specific topics |
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 four small helpful templates, {{yes}}, {{no}}, {{partial}} 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! |
{{partial}} |
Partial | {{partial|Maybe...}} |
Maybe... |
{{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"
instead of class="wikitable"
.
Columns can be made non-sortable using the attribute class="unsortable"
.
{| class="wikitable sortable" ! Cell one !! Cell two ! class="unsortable" | 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 |