Help:Tables

Writing tables in wiki code is difficult from the get-go, but it is significantly easier if you have experience with creating tables using HTML. On that note, HTML can also be used to create tables within the wiki. In this tutorial, we will be using HTML along side the wiki code to provide a better understanding of both.

Note on HTML
Throughout this article, HTML and Wiki Code are shown side by side. The reason for this is twofold: So those experienced with HTML can look at the HTML code and have a better idea of what is going on, and so those who don't know HTML table code can learn both.

Building Blocks
In HTML, table tags are used to begin and end a table. A similar idea is present in wiki code, using the curled bracket and pipe to begin and end a table. Note that these have to be the first characters on a line, or they will be ignored by the wiki. Examples: This forms the containing body of the table.
 * HTML
 * Open table: &lt;table&gt;
 * Close table: &lt;/table&gt;
 * WIKI
 * Open table: {|
 * Close table: |}

Next is the rows. In HTML, a opening and closing tag is required to begin and end a row. This is different in Wiki code, as a single set of a pipe and dash (followed by hitting enter once) and is needed only at the start of a new row. Examples: Rows contain the cells.
 * HTML
 * Begin row: &lt;tr&gt;
 * End row: &lt;/tr&gt;
 * WIKI
 * Begin row: |-

Finnally, of the basic structure, there are cells. In HTML, a cell is defined by it's opening and closing tags. As with rows, the wiki equivalent is also fairly different using a simple pipe to begin a cell, and a double pipe to separate cells on the same line. Example: Cells contain the table's actual content.
 * HTML
 * Begin cell: &lt;td&gt;
 * End cell: &lt;/td&gt;
 * WIKI
 * Begin cell: |
 * Separate cells: || (or press enter)

Putting Them Together
{| width="75%" style="border: solid 1px #aaaaff" cellpadding="4" cellspacing="1"
 * bgcolor="#eeeeff" | HTML TABLE
 * bgcolor="#ddddff" | WIKI TABLE
 * bgcolor="#ddddff" style="border: solid 1px #aaaaff" colspan="2" align="left" | Step 1 - Starting the table
 * - valign="bottom"
 * bgcolor="#eeeeff" width="50%" align="left" | To begin our basic HTML table, we start with the opening tag, &lt;table&gt;. I perfer to hit enter immediately after this tag so it's easier to find the beginning of the table.
 * - valign="bottom"
 * bgcolor="#eeeeff" width="50%" align="left" | To begin our basic HTML table, we start with the opening tag, &lt;table&gt;. I perfer to hit enter immediately after this tag so it's easier to find the beginning of the table.

&lt;table&gt;
 * bgcolor="#ddddff" width="50%" align="left" | To begin our basic wiki table, we start with the opening characters,  {| . Unless you are putting tags here, hitting enter is necessary.

{|
 * bgcolor="#ddddff" style="border: solid 1px #aaaaff" colspan="2" align="left" | Step 2 - Starting a row
 * - valign="bottom"
 * align="left" bgcolor="#eeeeff" | Next, we have to add our first row, by using the &lt;tr&gt; tag.
 * align="left" bgcolor="#eeeeff" | Next, we have to add our first row, by using the &lt;tr&gt; tag.

&lt;table&gt; &lt;tr&gt;
 * bgcolor="#ddddff" align="left" | Next, we have to add our first row, by using the characters  |- . Again, unless you are putting tags here, hitting enter is necessary.

{| |-
 * bgcolor="#ddddff" style="border: solid 1px #aaaaff" colspan="2" align="left" | Step 3 - Adding a cell
 * - valign="bottom"
 * align="left" bgcolor="#eeeeff" | Next, we have to add our first cell, by using the &lt;td&gt; and &lt;/td&gt; tags. We'll also be putting some content between them.
 * align="left" bgcolor="#eeeeff" | Next, we have to add our first cell, by using the &lt;td&gt; and &lt;/td&gt; tags. We'll also be putting some content between them.

&lt;table&gt; &lt;tr&gt; &lt;td&gt;This is content&lt;/td&gt;
 * bgcolor="#ddddff" align="left" | Next, we have to add our first cell, by using the |  character. Unless you are putting tags here, the content come immediately after.  No closing "tag" is needed.

{| |-  | This is content
 * bgcolor="#ddddff" style="border: solid 1px #aaaaff" colspan="2" align="left" | Step 4 - Adding another cell. Note: If you do not wish to add another cell, skip this step.
 * - valign="bottom"
 * align="left" bgcolor="#eeeeff" | Next, we will add our second cell, by using the &lt;td&gt; and &lt;/td&gt; tags again. We'll be putting some content between them as well.
 * align="left" bgcolor="#eeeeff" | Next, we will add our second cell, by using the &lt;td&gt; and &lt;/td&gt; tags again. We'll be putting some content between them as well.

&lt;table&gt; &lt;tr&gt; &lt;td&gt;This is content&lt;/td&gt; &lt;td&gt;This is more content&lt;/td&gt;
 * bgcolor="#ddddff" align="left" | Next, we will add our second cell, by pressing enter, and using the  |  character again. We'll be putting some content here as well. Alternatively, instead of pressing enter and adding a new  | , you can instead simply add  ||  on the same line, and add the content there. The example to the right uses the former method.

{| |-  | This is content | This is more content
 * bgcolor="#ddddff" style="border: solid 1px #aaaaff" colspan="2" align="left" | Step 5 - Finishing off the row.
 * - valign="bottom"
 * align="left" bgcolor="#eeeeff" | To end the row, simply add the &lt;/tr&gt; tag.
 * align="left" bgcolor="#eeeeff" | To end the row, simply add the &lt;/tr&gt; tag.

&lt;table&gt; &lt;tr&gt; &lt;td&gt;This is content&lt;/td&gt; &lt;td&gt;This is more content&lt;/td&gt; &lt;/tr&gt;
 * bgcolor="#ddddff" align="left" | This step is not needed using wiki table code.

{| |-  | This is content | This is more content
 * bgcolor="#ddddff" style="border: solid 1px #aaaaff" colspan="2" align="left" | Step 6 - Adding another row. Note: If you do not wish to add another row, skip this step.
 * - valign="bottom"
 * align="left" bgcolor="#eeeeff" | To add another row, repeat steps 2 Thru 5.
 * align="left" bgcolor="#eeeeff" | To add another row, repeat steps 2 Thru 5.

&lt;table&gt; &lt;tr&gt; &lt;td&gt;This is content&lt;/td&gt; &lt;td&gt;This is more content&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;This is even more content&lt;/td&gt; &lt;td&gt;This is EVEN MORE content&lt;/td&gt; &lt;/tr&gt;
 * bgcolor="#ddddff" align="left" | To add another row, repeat steps 2 Thru 5.

Advanced Formatting
Generally, the exact same attributes can be added to both HTML Table Tags and Wiki Tables to produce the same, or similiar results.

Background Color
The following works with both HTML and Wiki syntax:

The following can also be used on HTML and Wiki tables, and uses "style" statements.:

The above will change the background color of an entire table, row or a single cell, depending on where it is put. Note that either Hexadecimal Color Codes or Color Names can be used. Using names is highly encouraged. Row's color overrides table's color, and cell's overrides row's color. To color a column, you have to set every cells's color invidually.

Example:

Width and height
You can set the width and height of the whole table, and width of a column and heigh of a row. To set the width of a column, you must specify width of a single cell on that column.

The syntax is

Either of these would create a table that fills 80% of the screen horizontally, and is exacly 100 pixels high.

Example using "style" syntax:

Cell Spacing and Padding
Cell padding and spacing are two mostly overlooked features of tables. Cellpadding is the margins of a cell, and cellspacing is the distance between them. Observe the following.

{| style="border: solid 1px #a0a0ff" cellpadding="10"
 * - bgcolor="#eeeeff"
 * align="center" colspan="2" | Cellspacing
 * align="center" colspan="2" | Cellpadding
 * - bgcolor="#eeeeff"
 * align="center" | Normal
 * align="center" | Cellspacing of 10 pixels
 * align="center" | Normal
 * align="center" | Cellpadding of 10 pixels
 * - bgcolor="#eeeeff"
 * align="center" valign="center" |
 * align="center" valign="center" |
 * align="center" valign="center" |

{ | border="1px" cellspacing="10" | - | Cell X | Cell Y | - | Cell Z | Cell Q | } { | border="1px" cellpadding="10" | - | Cell X | Cell Y | - | Cell Z | Cell Q | } &lt;table border="1px" cellspacing="10"> &lt;tr> &lt;td>Cell X&lt;/td> &lt;td>Cell Y&lt;/td> &lt;/tr> &lt;tr> &lt;td>Cell Z&lt;/td> &lt;td>Cell Q&lt;/td> &lt;/tr> &lt;/table> &lt;table border="1px" cellpadding="10"> &lt;tr> &lt;td>Cell X&lt;/td> &lt;td>Cell Y&lt;/td> &lt;/tr> &lt;tr> &lt;td>Cell Z&lt;/td> &lt;td>Cell Q&lt;/td> &lt;/tr> &lt;/table>
 * align="center" valign="center" |
 * - bgcolor="#eeeeff"
 * align="center" colspan="4" | Wiki Code for the Above
 * - bgcolor="#eeeeff"
 * align="left" colspan="2" |
 * align="left" colspan="2" |
 * - bgcolor="#eeeeff"
 * align="center" colspan="4" | HTML Code for the Above
 * - bgcolor="#eeeeff"
 * align="left" colspan="2" |
 * align="left" colspan="2" |
 * }

Positioning
You can position the whole table, content of a single row or content of a single cell. You can define positioning in either horizontal or vertical direction.

align
align keyword controls the horizontal positioning. Normally everything is positioned to the left. align has two possible values: right and center.

The location of align word controls the word's scope. See following examples for clarification.

Whole table, right

Result:

Note that aligning tables to right might cause unexpected results with some browsers. In some cases the table will overlap other elements on the page.

Whole table, center

Result:

Row, right:

Result:

Row, center:

Result:

Notice that in both examples only the first row was affected. To align also the other rows to the right you would need to put align to every row, or alternatively use text-align with style:

Text-align:

Result:

Cells follow the same principle, align will only affect one cell. They will otherwise work as rows.

valign
valign, or vertical align, controls the vertical position of the text. valign can have to values, top or bottom.

Compare these two examples. On the left, no valign tags are used. On the right, both top and bottom tags are used, top for the middle row and bottom for the bottom row. As you can see on the left size, the default for vertical alignment is middle.

{|
 * align="center"|
 * align="center"|


 * align="center"|


 * }

Row and Column Span
There are two attributes, rowspan and colspan, that can expland cells accross rows and columns, respectively.

Example Syntax

These are placed where the cell's attributes would go, as show in the examples below.