|
<table border="1" cellpadding="2"> <caption>Multiplication table</caption> <tr><th>×</th><th>1</th><th>2</th><th>3</th></tr> <tr><th>1</th><td>1</td><td>2</td><td>3</td></tr> <tr><th>2</th><td>2</td><td>4</td><td>6</td></tr> <tr><th>3</th><td>3</td><td>6</td><td>9</td></tr> <tr><th>4</th><td>4</td><td>8</td><td>12</td></tr> <tr><th>5</th><td>5</td><td>10</td><td>15</td></tr> </table>
Multiplication table × 1 2 3 1 1 2 3 2 2 4 6 3 3 6 9 4 4 8 12 5 5 10 15
The important things to note in the example:
<table ...>
and ends with the required </table>
caption
element just after the initial <table>
tag
<tr>
and end with the optional </tr>
<th>
and end with the optional </th>
<td>
and end with the optional </td>
The td
and th
elements are sometimes called "cells", somewhat like the cells in a spreadsheet. Each row must have the same number of cells as the other rows, so that the number of columns in the table remains consistent (unless there are cells which span several columns or rows, but this is not discussed here). For empty cells, use the non-breaking space "
" as content, otherwise some browsers may not format the table properly.
If your table doesn't look right, make sure that all of the HTML tags are properly nested. You may find it easier to leave out the optional closing tags for some elements, since they are not strictly required in HTML. The best way to find errors in your table, though, is to check the article using the W3C MarkUp Validation Service (http://validator.w3.org/). Simply copy the URL of your article and paste it into the validator's address box. This service is especially useful for large, complex tables that would be difficult to check visually.
The sample above without the optional closing tags looks as follows:
Besides being shorter, this makes the page easier to maintain and less error-prone.<table border="1" cellpadding="2"> <caption>Multiplication table</caption> <tr><th>×<th>1<th>2<th>3 <tr><th>1<td>1<td>2<td>3 <tr><th>2<td>2<td>4<td>6 <tr><th>3<td>3<td>6<td>9 <tr><th>4<td>4<td>8<td>12 <tr><th>5<td>5<td>10<td>15 </table>
If you are already familiar with HTML tables, you may want to note that the thead
, tbody
, and tfoot
elements are currently unsupported in Wikipedia.
Here's a more advanced example, showing some more options available for making up tables. You can play with these settings in your own table to see what effect they have. Not all of these techniques may be appropriate in all cases; just because you can add colored backgrounds, for example, doesn't mean it's always a good idea. Try to keep the markup in your tables relatively simple -- remember, other people are going to be editing the article too! This example should give you an idea of what is possible, though.
<table border="1" cellpadding="5" cellspacing="0" align="center"> <caption>'''An example table'''</caption> <tr> <th style="background:#efefef;">First header</th> <th colspan="2" style="background:#ffdead;">Second header</th> </tr> <tr> <td>upper left</td> <td> </td> <td rowspan=2 style="border-bottom:3px solid grey;" valign="top"> right side</td> </tr> <tr> <td style="border-bottom:3px solid grey;">lower left</td> <td style="border-bottom:3px solid grey;">lower middle</td> </tr> <tr> <td colspan="3" align="center"> <table border="0"> <caption>''A table in a table''</caption> <tr> <td align="center" width="150px">[[Image:wiki.png]]</td> <td align="center" width="150px">[[Image:wiki.png]]</td> </tr> <tr> <td align="center" colspan="2" style="border-top:1px solid red; border-right:1px solid red; border-bottom:2px solid red; border-left:1px solid red;"> Two Wikipedia logos</td> </tr> </table> </td> </tr> </table>
An example table First header Second header upper left right side lower left lower middle
A table in a table Two Wikipedia logos
Tables are perfect for organizing any information that is best presented in a row-and-column format. This might include:
Many times, a list is best left as a list. Some articles include excessively long lists which would be very difficult to edit if they were in table form. Before you format a list in table form, consider whether the information will be more clearly conveyed by virtue of having rows and columns. If so, then a table is probably a good choice. If there is no obvious benefit to having rows and columns, then a table is probably not the best choice.
Tables shouldn't be used simply for layout, either. If the information you're editing isn't tabular in nature, it probably doesn't belong in a table. Try not to use tables for putting a caption under a photograph, arranging a group of links, or other strictly visual features. It makes the article harder to edit for other Wikipedians, and isn't really what tables were designed to do.
If a list is quite long, or is relatively simple, use one of the standard Wikipedia list formats. Long lists can be hard to maintain if they are inside a table, and simple lists are (simply) too simple to need the row-and-column format that a table provides. Here are some examples of things that might be better done with lists instead of tables.
Year Album 1980 Ultra Wave 1988 What's Bootsy Doin'? 1994 Blasters of the Universe 1994 Fresh Outta 'P' University
- 1980 - Ultra Wave
- 1988 - What's Bootsy Doin'?
- 1994 - Blasters of the Universe
- 1994 - Fresh Outta 'P' University
Many times, images in an article are placed using a quirk of table rendering. Because a table can be floated to the left or right side of the screen, it has become common practice to utilize a simple one-celled table to place an image in a particular part of the screen. This was a necessary workaround for old browsers, since it generates a consistent rendering of images in browsers which do not adequately support Cascading Style Sheets. By far, the majority of browsers in use today, however, should do just fine with style sheets. The recommended practice now is to arrange images using an element called div
.
For detailed instructions, see Wikipedia:Image use policy and the Wikipedia:Image markup gallery. Here's a brief example, though:
<table align="right" border="0" cellpadding="0"><tr><td>[[Image:Covalent.png]]</td></tr></table>
<div style="float:right; margin: 0 0 1em 1em;">[[Image:Covalent.png]]</div>
Covalent bonding most frequently occurs between atoms with similar electronegativities, where neither atom can provide sufficient energy to completely remove an electron from the other atom. Covalent bonds are more common between non-metals, whereas ionic bonding is more common between two metal atoms or a metal and a non-metal atom.
Covalent bonding tends to be stronger than other types of bonding, such as ionic bonding. In addition unlike ionic bonding, where ions are held together by a non-directional coulombic attraction, covalent bonds are highly directional. As a result, covalently bonded molecules tend to form in a relatively small number of characteristic shapes, exhibiting specific bonding angles.
Tables may cause other difficulties, even when used appropriately. Here are some issues you may want to consider if you use tables in your articles:
code
, pre
, or tt
elements, for example), it may force the page to be wider than necessary. Whenever possible, avoid using fixed-width text inside tables, so the text can flow naturally. A similar problem can happen if you include images inside tables (since images are usually constrained to be a fixed width).
Search Encyclopedia
|
Featured Article
|