Help:Tables

From QED

Jump to: navigation, search
Help
Related topics

For general help about tables, see Help:Table. For some examples, visit this gallery.

For help about color names that can be used with tables, see Color Names.

Contents

Predefined Table Classes

There are some table classes which are universally available. They are defined on the MediaWiki:Common.css page and currently include wikitable and sortable.

For example, the effect of adding class=wikitable is illustrated by the following:

Glyph Entity Name
© ©
   
Glyph Entity Name
© ©

The above table on the right was produced by the following wikitable markup:

{| class=wikitable
! Glyph !! Entity Name
|-
| © || ©
|-
|} 

Sortable Tables

Sortable tables can be created on a page by using wikitable and/or HTML syntax.

For example, you should be able to sort the rows of the following table in various ways by clicking on the column headings.

M N A
12 78 a
14 76 xyz
16 74 ab

Notice the vertical arrows that appear.

Here is the same table using class="sortable wikitable":

M N A
12 78 a
14 76 xyz
16 74 ab

Notes

  • class=sortable is only intended for use with simple tables (matrices).
  • A column's type is determined by the first non-blank data element in the selected column.
  • All rows in the body of the table will be sorted except for the last row if it is marked "class=sortbottom" (see below).
  • All columns will be marked as sortable except for columns marked "class=unsortable" (see below).
  • The following types are currently recognized:
    • dates (DD-MM-YYYY or DD-MM-YY or DD AAA YYYY)
    • currencies ($, £, €, or ¥)
    • numbers
    • parenthesized numbers (this is a QED extension)
    • strings

For further details, see Help:Sorting but note that currently, type declarations are not yet supported.

Sortable Tables with wikitable Syntax

Simply mark your table as sortable, e.g. by declaring class=sortable or class="sortable wikitable", as shown using the following wikimarkup, which is rendered as shown above:

{| class=sortable
|-
!  M ||  N ||  A
|-
| 12 || 78 || a
|-
| 14 || 76 || xyz
|-
| 16 || 74 || ab
|}

class=unsortable and class=sortbottom

The following wikimarkup produces the table below:

{| class="wikitable sortable" style="text-align:right"
!Numberic!!Alphabetic!!Dates!!Currency!!class="unsortable"|Unsortable
|-
|1||Z||02-02-2004||5.00||This
|-
|2||y||13-apr-2005||||Column
|-
|3||X||17.aug.2006||6.50||Is
|-
|4||w||01.Jan.2005||4.20||Actually
|-
|5||V||05/12/2006||7.15||Unsortable
|- class="sortbottom" 
! Totals:{{repeat| |6}} 15!! !! !! {{repeat| |10}} 29.55 !!
|-
|}
NumericAlphabeticDatesCurrencyUnsortable
1Z02-02-20045.00This
2y13-apr-2005Column
3X17.aug.20066.50Is
4w01.Jan.20054.20Actually
5V05/12/20067.15Unsortable
Totals:       15            29.55

The non-breaking spaces ( ) are for alignment.

Sortable Tables with HTML Syntax

To specify that a table is to be interactively sortable, add "sortable" to the table's list of classes as illustrated above.

For example:

<table class="sortable">

Examples

To see the HTML, press the page's edit or view tab, or the section's edit link if it appears.

NameSalaryExtensionStart date
Bloggs, Fred$12000.00 135318/08/2003
Turvey, Kevin$191200.00 234202/05/1979
Mbogo, Arnold$32010.12 275509/08/1998
Shakespeare, Bill$122000.00 321112/11/1961
Shakespeare, Hamnet$9000.00 900501/01/2002
Fitz, Marvin$3300.00 555422/05/1995


Vegetable Cost per kilo
Lettuce $1.00
Silver carrots $10.50
Golden turnips $100.30


Alignment

The alignment of the content of cells within a table is governed by cell-specific specifications, row-specific specifications, and table-specific specifications. The most specific specification overrides all others.

There is no direct way to specify alignment for a specific column.

For horizontal alignment, style="text-align:X;" may be used, where X is one of left, right, center, or justified.

Example

In this example, the specification for the table as a whole is "text-align:right" but the headings each have their own specifications:

{| style="text-align:right"
!width=100 align=left|LEFT
!width=100 align=center|CENTER
!width=100 align=right|RIGHT
|-
| a || b || c
|}

produces:

LEFT CENTER RIGHT
a b c

Alignment of Columns of Consecutive Tables

One approach is to specify the width of the corresponding columns as a percentage, as illustrated here:

8th century

Year Date Event
795 First Viking raids

9th century

Year Date Event
852 Vikings Ivar Beinlaus and Olaf the White land in Dublin Bay

The wikitext for the first of these two tables is as follows:

{| class="wikitable" width="100%"
! style="width:6%" | Year || style="width:10%" | Date || Event
|-
| 795 ||  || First Viking raids
|}

Quizzes

The <memorize> tag allows tables to be turned into interactive quizzes, as illustrated by the following example.

Flags
Polity (memorize) Flag (memorize)
Australia
CIS
EU

To turn the table into a quiz, click on one of the memorize links. See Help:Memorize for further details.

Conversion to and from WikiTable Syntax

An online copy-and-paste tool for converting from spreadsheets such as Microsoft Excel is available here.

A fast, online, and accurate service for converting to or from HTML table syntax is available here.

Other services are described here.

Table-Related Templates

The following table illustrates Template:yes, Template:no, Template:dunno, and Template:partial:

name {{name|}} {{name}} {{name|text}}
yes Yes Oui
no No Non
dunno  ? n.a.
partial Partial Comme ci comma ça

For example, the "yes" row above is generated by the following line:

 | yes || {{yes|}} || {{yes}} || {{yes|Oui}} 


The {{rh}} "row-header" template is also often useful:

{{rh}} | {{rh}} | Header Style
Header Style
plain cell

For other Table cell templates, see Template:Table cell templates.

For other table-related templates, see Category:Table Template.

See also

Personal tools