Help:Wiki University Wikitext--Tables - Column Spans
Lessons
- HOME
- Introduction
- Headers
- Lists
- Nesting Lists
- Links
- Broken Links
- Comments
- Categories
- Image Embedding
- Image Tooltips & Borders
- Image Links
- Images & Text; Embedding PDF
- Snipping Tool & Paint
- Paragraphs
- Inline Styling
- Changing Fonts
- Font Colors
- Backgrounds
- Multi-attributes
- Font Bold-Italics
- Div Tag - Intro
- Borders
- Padding
- Margins
- Width and Height
- Alignment - Horizontal
- Tables
- Breadcrumb Trails
- Ref/Footnotes
- SEO
Intermediate
Advanced
Flexbox
Additional Helps
Spanning columns in tables[edit | edit source]
- When we create tables, sometimes we want a cell to cover more than one column like in the following example:
Foods with short shelf life | Foods with long shelf life | ||
Fruits | Vegetable | Nuts | Grains |
---|---|---|---|
Apples | Peas | Peanuts | Wheat |
Pears | Carrots | Walnuts | Oats |
Cherries | Corn | Cashews | Barley |
Orange | Beans | Almonds | Buckwheat |
- NOTICE the first row consists of two cells, each spanning two cells of the following row.
This ability to span columns is especially useful when separating sections of one table into different topics.
How to span columns[edit | edit source]
- If we want to span two columns, for example, we use a class[1] called "colspan."
- This coding is inserted right after either the | or ! tags.
- When using the pipe "|", you will need to add in the "text-align:center" attribute in order for the name to be centered:
- If you use the "!" instead of the pipe "|", then the name defaults to the center and is bolded:
- Here is the coding for the first three rows of the above table using a pipe:
{| style="border:1px solid red"
|+ style="font-size:14pt; " | Healthy Foods
|-
| colspan="2" style="border:1px solid red; text-align:center; background-color:wheat" | Foods with short shelf life
| colspan="2" style="border:1px solid red; text-align:center; background-color:wheat" | Foods with long shelf life
|-
! style="width:25%; border:1px solid red" | Fruits
! style="width:25%; border:1px solid red" | Vegetable
! style="width:25%; border:1px solid red" | Nuts
! style="width:25%; border:1px solid red" | Grains
|-
| style="border:1px solid red" | Apples
| style="border:1px solid red" | Peas
| style="border:1px solid red" | Peanuts
| style="border:1px solid red" | Wheat
|-
.
.
.
|}
- NOTICE again the location of the class "colspan."
- NOTICE a pipe needs to be added before the title, separating it from the colspan and style commands.
- NOTICE that the new row only has two cells, but each cell has a "colspan" in it. The two colspans cover the four cells in the next row.
Columns have to add up[edit | edit source]
- Make sure that the columns you span add up to the total number of cells in the next row.
- If you span a total of four columns or cells, you must have two colspan="2" in the preceding row, otherwise you will get who knows what!
Restrictions[edit | edit source]
- You cannot create sortable tables with colspans.
Try these out[edit | edit source]
- Use this coding for a table
{| style="border:1px solid red; width:100%"
|-
! style="border:1px solid red; width:25%" | Fruits
! style="border:1px solid red; width:25%" | Vegetable
! style="border:1px solid red; width:25%" | Nuts
! style="border:1px solid red; width:25%" | Grains
|-
| style="border:1px solid red" | Apples
| style="border:1px solid red" | Peas
| style="border:1px solid red" | Peanuts
| style="border:1px solid red" | Wheat
|-
| style="border:1px solid red" | Pears
| style="border:1px solid red" | Carrots
| style="border:1px solid red" | Walnuts
| style="border:1px solid red" | Oats
|-
| style="border:1px solid red" | Cherries
| style="border:1px solid red" | Corn
| style="border:1px solid red" | Cashews
| style="border:1px solid red" | Barley
|-
| style="border:1px solid red" | Orange
| style="border:1px solid red" | Beans
| style="border:1px solid red" | Almonds
| style="border:1px solid red" | Buckwheat
|}
- Merge all the cells in the second row.
- Merge the first three cells in the last row.
- Colspans must equal the number of cells in the next row.
- A. True
- B. False
- If you have a row with four cells you can have in the preceding row one cell with a colspan="3" plus the remaining cell.
- A. True
- B. False
- If you have a row of seven cells you can have in the preceding row one cell with a colspan="2", the next cell with a colspan="3" and the remaining cell with a colspan="2".
- A. True
- B. False
- ↑ This is another built in wikitext mini-program.