Help:Table/Manual tables

From Wikipedia, the free encyclopedia
Jump to: navigation, search


Introduction to tables
What are they for and how do I make them?

Creating tables manually
Want more control over tables? Go here

Sortable tables
How to make tables sortable

HTML and tables
How to use HTML with tables


If you don't have a way of creating tables automatically, or want more control over them, this tutorial should explain how. So, a basic table, as discussed, is:

{| class="wikitable"
|-
! header 1
! header 2
! header 3
|-
| row 1, cell 1
| row 1, cell 2
| row 1, cell 3
|-
| row 2, cell 1
| row 2, cell 2
| row 2, cell 3
|}

This would produce:

header 1 header 2 header 3
row 1, cell 1 row 1, cell 2 row 1, cell 3
row 2, cell 1 row 2, cell 2 row 2, cell 3

As you can see, columns headers are created by ! column name. Cells are created by | cell text. The divider between rows is |-. You can add an extra column by just sticking ! new column name at the end of the last column name. To fill the cells in that column, you need to add another cell to each row: fill it by typing |cell text. If you want to add an extra row, just add |- to the table, and fill it with however many cells are appropriate.

To recap, the markup is:

{|

table start: required!

|+

table caption: optional. Only between table start and first table row

!

table header cell: optional. Consecutive cells may be added on same lines separated by double marks (!!); or start on new lines, each beginning with its own single mark (!).

|-

table row: optional on first row, otherwise required. The wiki engine assumes the first row.

|

table data cell: required! Consecutive cells may be added on same lines separated by double marks (||); or start on new lines, each beginning with its own single mark (|). Single marks are also used to separate HTML attributes from cell contents (both data or header), or caption contents.

|}

table end: required!
  • Blank spaces at the beginning of a line are ignored.
  • Escaping to insert a pipe (|) character into a table can be done using the <nowiki> markup.


using || and !! with tables

The above markup must start on a new line. This includes the cell markup (| and !). But the double cell markup (|| and !!) can optionally be used for adding consecutive cells to a single line.

For example, this would produce the same table as above:

{| class="wikitable"
|-
! header 1 !! header 2 !! header 3
|-
| row 1, cell 1 || row 1, cell 2 || row 1, cell 3
|-
| row 2, cell 1 || row 2, cell 2 || row 2, cell 3
|}


wikitable

class="wikitable" is used with a lot of tables on Wikipedia, and adds some standard styling.


HTML attributes

  • All table markup, except table end (|}), optionally accepts one or more HTML attributes on the same line.
  • Cell markup (|, ||, !, !!) and caption markup (|+) hold content. So separate any attributes from content with a single pipe (|), even when cell content is on a new line, which is permissible.
  • Cell content may follow on the same line after its cell markup (which may include HTML attributes); or on lines below the cell markup. Cell content that uses its own markup may need to start on a new line; this can happen with things like lists, headings, or nested tables.
  • Table and row markup ({| and |-) do not directly hold content. Do not add pipe (|) after their optional attributes. An example is the class="wikitable" above. If a pipe is added improperly after attributes for the table or row markup, the parser will delete it and any final attribute that was touching the improper pipe.
  • See Help:Table/HTML and tables for some simple examples.