Help:Tables

From FlightGear wiki
Jump to navigation Jump to search


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" and style="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, |.
  • 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

External links