Help:Tables

From WikiLectures

Tables are useful when presenting sorted data, various therapeutic approaches or just a lot of numbers. How can you make a table in WikiLectures?

Basics on tables[edit | edit source]

Here are basic pieces of code that help create a table. Every piece of code must be followed by a space!

Code Description
{| table start
|+ table caption between table start and first table row
|- table row
! table header cell
| table data cell
|} table end

Simple table can be written as:

Code Preview
{|
! First column
! Second column
|-
| A
| B
|-
| C
| D
|}
First column Second column
A B
C D

This simple table can be inserted when you click a “Table” button from the “Advanced” tab in the edit toolbar above the edit field. Of course you can change number of rows or columns as you need.

Atributes[edit | edit source]

You can change the style of the table or create a more complicated table when using atributes. Let’s have a look at them.

Atribute “class” (better look or sorting options)[edit | edit source]

This atribute is used at table start to change the style of the table. For example, simple table looks like this:

{|
! A !! B
|-
| C || D
|}
A B
C D

If you want better looking table, you can add atribute class with value “wikitable”. This will do this table:

{| class="wikitable"
! A !! B
|-
| C || D
|}
A B
C D

If you want to sort the items in an alphabetical or numerical order, add atribute class with value “sortable”:

{| class="wikitable sortable"
! A !! B
|-
| 1 || A
|-
| 3 || C
|-
| 2 || B
|}
A B
1 A
3 C
2 B

Atribute “colspan” and “rowspan”[edit | edit source]

If you want to merge two columns, you have to use atribute colspan in the cell that you want to be merged with the value of number of cells merged. The next cells will be absent.

{| class="wikitable"
! First column
! Second column
! Third column
|-
| First cell
| colspan="2" | Second and third cell merged
|}
First column Second column Third column
First cell Second and third cell merged

If you want to merge two or more rows, the code is similar. Use the atribute rowspan. But be careful: the next rows must have smaller number of cells!

{| class="wikitable"
! First row
| First cell
| Second cell
|-
! Second row
| rowspan="2" | First cell
| Second cell
|-
! Third row
| Second cell
|}
First row First cell Second cell
Second row First cell Second cell
Third row Second cell