Help:Tables

Tables are commonly used on UESP to organize information into columns.  Although traditional HTML tags can be used to create a table (  ,  ,   , etc.), the wiki software introduces a new set of table markup tags.  This article focuses solely on the wiki table markup tags.

Introduction
A simple table looks like:


The code used to produce this table is:
  

The basic parts used to construct tables (as shown in this example) are:
    : marks the end of the table.

Table Structure
Definition
All tables must start with:
  
Although the wiki will try to fix the problem, the results are generally not what you wanted.  If you find that parts of your table are showing up in strange places on the page, make sure that you have closed all of your tables.  This   tag must be at the start of a new line to be recognized.

Rows
To start a new row of the table use:
 |-
The   tag must be at the start of a new line.  The contents of the row are not provided on the same row.

The only text that can be added following the   tag are parameters to change the formatting of the row.  For example:
 
This would make this one row all contain left-aligned text.  "left" can be replaced by "right" or "center" for right-aligned or center-aligned text, respectively.  This option applies only to the one row and will override any other options specified by the table's class or in the table's definition.  However, individual cells may override the general row formatting.
 
This makes all cells in the row be vertically "top-aligned", i.e., the text in the cells starts at the very top of the cell

Cells
Cells are generated either like this:
 |cell1
 |cell2
 |cell3
or like this:
 |cell1||cell2||cell3
The two types can be combined in various ways, e.g.
 |cel11||cell2
 |cell3

Any formatting options for the cell are supplied before the cell contents and separated from the contents using a   tag.  Adding alignment options to the previous examples would be done as:
 |style="text-align:left"|cell1
 |style="text-align:center"|cell2
 |style="text-align:left"|cell3
Or
 |style="text-align:left"|cell1 |style="text-align:center"|cell2 |style="text-align:left"|cell3
Or
 |style="text-align:left"|cell1 |style="text-align:center"|cell2
 |style="text-align:left"|cell3

Header Cells
Header cells are used to provide the column titles, and generally have bold text and a different background color for emphasis.  They are
specified similarly to standard Cells, except   or   is used instead the opening   or  .  When formatting is being provided for a header cell, one   and one   must be combined:
 !style="text-align:left"|cell1

Header cells can be specified anywhere in a table if desired, for example the fourth column in every row could be made into a "header" format.

Captions
Captions are not generally used with UESP tables.  If you need to create one, however, use the tag:
 |+ Caption

Options
Classes
UESP has several pre-defined classes that provide the tables on the site with a uniform appearance and allow editors to quickly and easily create tables without learning detailed table formatting commands.  These classes are defined in the site's CSS files and can only be modified by the site's Administrators.

The three classes used to specify overall table layout are:
 : The standard table layout used for nearly every table on UESP.
 : For tables that are used solely for organizing information where no table borders, margins, or backgrounds are desired.  In many cases, this format of table is possible simply by omitting the class option from the table definition.  However, there are situations such as nested tables where the hiddentable class is necessary.
 : For manually created tables of contents.

 
|
   
|
   
|-
|

|

|

|}

Additional classes exist that can be used to provide other formatting details.  These classes are designed to be used in conjunction with one of the basic layout classes.  For example,   (note that the optional classes follow the primary "wikitable" class).  The available options are:
 : Centers the table horizontally on the page.
 : Eliminates all padding and margins to create smaller tables.
 : First column is left-aligned, the rest of the table is center-aligned.
 : Sets all cells in the table to have valign=middle (i.e., the content is all aligned vertically in the middle of the cell).
 : Sets all cells in the table to have valign=top (i.e., the content is all aligned vertically at the top of the cell).  This is the default setting for tables, and therefore generally does not need to be used.

Sortable Tables
Another class that can be added for extra table features is  .  With this option, an icon is added to the header of each column; clicking on the icon causes the entire table to be sorted based upon the values in that column.

 
|width=50%|

|}

You can remove the sort icon from a column by giving the header the "unsortable" class.  This example also adds the   option (see notes below):
 
|width=50%|

|}
Keep in mind that only one row can be bottom-sorted in this way, and there is no way to top-sort a row. 

UESP's implementation of sortable tables is not the same as standard mediawiki sortable tables.  Some additional features on UESP:
Adding the class   to the table in addition to   will cause every other row to automatically have a light gray background.  This striping is updated every time the table is sorted (demonstrated in the second demo table above).
Row-spanning and column-spanning cells are supported in sortable tables
Rowspan groups of rows are always kept together as a fixed unit when sorting
Format of a column can be specified, by setting the class of the first cell in the column.  Particularly useful if column contains blank cells.  Any cells that do not match specified class are treated as blank.  Possible classes are:
sort_num: sort column numerically
sort_date: sort column as a date
sort_str: sort column as a string
Column can be set to by default sort in descending order (with one click, instead of having to click twice for descending order).  Selected by setting class of the first cell in the column:
sort_desc: descending sort order
Minor features:
Clicking on a column three times reverts the entire table to its original layout.
Line breaks (   
|width=50%|

|}

 
|width=50%|

|}

Floating Table
 
|width=50%|

|the original table again
|}
|}

Headers
 
|width=50%|

|}

See Also
Wikipedia Help:Table