Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Please sign up or log in to edit the wiki.

Purpose

To make it easier to align table columns with less code.
CSS:Template:Table alignment/styles.css
Taken from: Wikipedia:Template:Table_alignment

Usage

Place {{Table alignment}} above the table and then add some classes to the table.

Classes for table start wikitext: {| class="class1 class2".
Class Summary
defaultleft Align all table cells left by default. May not be needed since cells are normally left-aligned already.
defaultcenter Align all table cells center by default.
defaultright Align all table cells right by default.
colNleft Align the cells in column N left, where N is a number.
colNcenter Align the cells in column N center, where N is a number.
colNright Align the cells in column N right, where N is a number.
col-Nleft Align the cells in column N left counting from the right, where N is a number.
col-Ncenter Align the cells in column N center counting from the right, where N is a number.
col-Nright Align the cells in column N right counting from the right, where N is a number.

The col classes override the default classes. The col classes never affect header cells (column or row). The default classes affect header cells only when the wikitable class is not used.

A 5-column wikitable using defaultright, col2left, and col-1left
col header col header col header col header col header
row header col2 col3 col4 col5
row header col-4 col-3 col-2 col-1

Limitations

  • Preview will not work unless {{table alignment}} is in that section. But if it is placed anywhere on the page, then table alignment will occur upon publishing. So to avoid bafflement and confusion by editors previewing sections, put it directly above each table its classes are used in. This is true for any table template using TemplateStyles.
  • Column numbers up to col29 (left-most 29) and col-9 (right-most 9) are supported. A table can have more columns but it cannot be aligned with this method.
  • On tables using rowspan or colspan, using the classes may not work well on those rows because the alignment appears in wrong cells. Normal table code like style="text-align: left/center/right;" | cell content can be added to individual cells, both to get the wanted alignment and override unwanted alignment.

Example

Header Header Header Header
AAAAAAA 10000–20000 3–4 53.43
BBB 5–6 113–125 2563.35
CCC 9–10 7–8 313.00
Header Header Header Header
AAAAAAA 10000–20000 3–4 53.43
BBB 5–6 113–125 2563.35
CCC 9–10 7–8 313.00

Example with rowspan

Fix rowspan issues by adding text-align inline styles.

Header Header Header Header
AAAAAAA 10000–20000 3–4 53.43
BBB 5–6 113–125 2563.35
9–10 7–8 313.00
Header Header Header Header
AAAAAAA 10000–20000 3–4 53.43
BBB 5–6 113–125 2563.35
9–10 7–8 313.00