Help:Tables

Tables are a very useful tool for presenting data neatly. There are many different ways of using wikicode, HTML, and CSS, to achieve the desired appearance of the table, although in most situations, only the basics are required. Experiment in the Sandbox to get a feel for designing tables, and don't hesitate to ask for help where necessary.

Basic coding

 * Important: Each code must be placed at the beginning of a new line. However, an entire row may be placed on one line, by duplicating the code used to begin the row. This is explained further below.

Simple tables

 * The same table, with an added caption.
 * The same table, with the wikicode contained on one line per row.
 * An extended table, with randomly added header cells. Any cell can be designated as a "header" by using the ! mark. Note that this effect cannot be achieved with the wikicode contained on one line per row.
 * }
 * The same table, with the wikicode contained on one line per row.
 * An extended table, with randomly added header cells. Any cell can be designated as a "header" by using the ! mark. Note that this effect cannot be achieved with the wikicode contained on one line per row.
 * }
 * An extended table, with randomly added header cells. Any cell can be designated as a "header" by using the ! mark. Note that this effect cannot be achieved with the wikicode contained on one line per row.
 * }
 * An extended table, with randomly added header cells. Any cell can be designated as a "header" by using the ! mark. Note that this effect cannot be achieved with the wikicode contained on one line per row.
 * }
 * }
 * }
 * }

Adding CSS attributes to tables and cells
It's possible to use CSS to customize the appearance of the table, and even individual cells. To make these attributes take effect throughout the entire table, add them to the same line as the "wikitable" class. To change the attributes of a single row, add the code to the line beginning with the table row marker. To change the attributes of a single cell, add the code after the pipe (|) at the beginning, and end the code with another pipe before adding the cell's content.

Note that HTML table attributes such as,  , and   are now deprecated, and should not be used as they may not work as intended. You should use CSS equivalents instead.

A table with the font color changed to red.

A table with one row's text centred.

A table with Cell 2 italicised.

Another way of coding the above.

Moving a caption to the left of the table, and coloring it blue.

colspan and rowspan: Irregular-sized cells
One cell can be made to span several rows or columns, by using the colspan and rowspan attributes. This has various useful applications. However, the fact that these attributes eliminate certain cells from other parts of the table's coding can significantly increase the overall complexity of the table. Using the Sandbox and the "Show preview" button to learn how these attributes affect a table's appearance is extremely helpful. The attributes accept a numerical value representing the number of rows or columns a single cell should span. This value should be no less than two, and no greater than the total number of rows or columns in the table. The attributes are added to a cell like a HTML or CSS attribute, as follows: |colspan="2"|Cell content

An example of a table using colspan :

rowspan is a little more difficult to code:

Sortable tables
Sortable tables are useful in tables that contain information that may benefit from being quickly sortable, either alphabetically or numerically. To make a sortable table, change the "wikitable" class at the top of the table to "wikitable sortable". This class places sorting buttons in the table's top headings. Clicking these sorts the entire table according to that column's data. To remove the sort button from a single column, add the "unsortable" class to that column's header. If a column contains a mixture of alphabetical and numerical data, the data will be grouped into the two separate types before sorting. Note that sorting is generally incompatible with colspan and rowspan.

Preventing the "Mix" column from being sorted: