User:42/SmTableGuide
42 notes
- Obviously, the links would need to be re-done to allow the links to connect to any applicable wiki or metawiki sections. This should be minimal if even needed at all.
- This is a very rough guide/idea presentation. The information from each section posted would (hopefully) be able to be posted directly from the actual metawiki table page.
- The majority of the below list is needed in a table help page. Since most of the needed information has already been done by someone, the most sensible way would be to re-use that information and examples already given.
- Spreadsheet to wiki table format (this section would be not included/removed on GWW table help)
- Using the toolbar (this section would be edited to add GWW specific notes, or not included from metawiki and have GWW specific information instead)
- Pipe syntax tutorial NEEDED
- Examples NEEDED
- Simple example NEEDED
- Multiplication table NEEDED
- Color; scope of parameters NEEDED
- Width, height NEEDED
- Setting your column widths NEEDED
- Vertical alignment NEEDED
- Positioning NEEDED
- Mélange NEEDED
- Floating table NEEDED
- Nested tables NEEDED
- Combined use of COLSPAN and ROWSPAN NEEDED
- Centering tables NEEDED
- Setting parameters NEEDED
- Decimal point alignment (slightly more advanced, could possibly do without)
- Style classes (this section would most likely not be inluded; more information than the average person would need to use)
- Sorting NEEDED (used quite often in various tables, and for many different subjects)
- Row template (unsure if this would be needed or not, could possibly do without this being on GWW table help)
- Conditional table row (not sure if this section would be needed or not, candidate for non-inlclusion on GWW table help)
- Other table syntax (this entire section would be not included/removed on GWW table help)
- Comparison of table syntax (removed)
- Pipe syntax in terms of the HTML produced (this entire section would be not included/removed on GWW table help)
- Tables (removed)
- Rows (removed)
- Cells (removed)
- Headers (removed)
- Captions (removed)
- Displaying the table code which generates a table (this section not needed for basic table editors, needed more for someone making a how-to guide)
- Other alternatives to display table code (removed)
- Square monitors (would be not included/removed on GWW table help)
- Viewing tables in email and web pages outside Wikipedia (would be not included/removed on GWW table help)
- See also
- External links (would be not included/removed on GWW table help, references for excel to wiki)
- Links to other help pages (might keep, might not, depends on the needs I guess)
This page gives you information about syntax to build wiki-tables in MediaWiki.
Spreadsheet to wiki table format[edit]
(would remove/not include this section from GWW form)
To convert from spreadsheets such as Gnumeric, MS Excel or OpenOffice.org Calc, see http://excel2wiki.net/.
Using the toolbar[edit]
(would keep this section, except possibly have our own GWW version/adaptation instead of straight content copy. else would add notes before or after to explain diffs between metawiki table and gww table)
You can use the Mediawiki edit toolbar to create tables on Wikipedia, and some Wikimedia projects. It is helpful to generate the necessary codings. However, on many MediaWiki wikis (and by default) the table tool is not available.
Use the first button on the right of the toolbar to insert a table when editing a page.
By default, it includes the following text:
{| 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 |}
Pipe syntax tutorial[edit]
Column heading 1 | Column heading 2 | Column heading 3 |
---|---|---|
Row heading 1 | Cell 2 | Cell 100 |
Row heading A | Cell B | Cell C |
Although HTML table syntax also works, special Wikicode can be used as a shortcut to create a table. The pipe (vertical bar) codes function exactly the same as HTML table markup, so a knowledge of HTML table code will help in understanding pipe code. The shortcuts are as follows:
- The entire table is encased with curly brackets and a vertical bar character (a pipe). So use
{|
to begin a table, and|}
to end it. Each one needs to be on its own line:
{| table code goes here |}
- An optional table caption is included with a line starting with a vertical bar and plus sign "
|+
" and the caption after it:
{|
|+ caption
table code goes here
|}
- To start a new table row, type a vertical bar and a hyphen on its own line: "
|-
". The codes for the cells in that row will start on the next line.
{| |+ The table's caption |- cell code goes here |- cell code goes here |}
- Type the codes for each table cell in the next row, starting with a bar:
{| |+ The table's caption |- | cell codes go here |- | cells in the next row go here | more cells in the same row here |}
- Cells can be separated with either a new line and new bar, or by a double bar "||" on the same line. Both produce the same output:
{| |+ The table's caption |- |Cell 1 || Cell 2 || Cell 3 |- |Cell A |Cell B |Cell C |}
- If you use single bars, then what might appear to be the first cell is in fact a format modifier applied to the cell, and the rest of your "cells" will be merged into one:
{| border="1" |- |format modifier (not displayed)|These all |(including the pipes)|go into |the first cell |- |}
which is probably not what you want:
These all |(including the pipes)|go into |the first cell |
However, the format modifier is useful:
{| border="1" |- |Cell 1 (no modifier - not aligned) |- |align="right" |Cell 2 (right aligned) |- |}
Cell 1 (no modifier - not aligned) |
Cell 2 (right aligned) |
Just remember: no more than 2 single pipes on a line!
- a row of column headings is identified by using "!" instead of "|", and using "!!" instead of "||". Header cells typically render differently from regular cells, depending on the browser. They are often rendered in a bold font and centered.
{|
|+ The table's caption
! Column heading 1 !! Column heading 2 !! Column heading 3
|-
|Cell 1 || Cell 2 || Cell 3
|-
|Cell A
|Cell B
|Cell C
|}
- the first cell of a row is identified as row heading by starting the line with "!" instead of "|", and starting subsequent data cells on a new line.
{| |+ The table's caption ! Column heading 1 !! Column heading 2 !! Column heading 3 |- ! Row heading 1 | Cell 2 || Cell 3 |- ! Row heading A |Cell B |Cell C |}
- Optional parameters can modify the behavior of cells, rows, or the entire table. For instance, a border could be added to the table:
{| border="1"
|+ The table's caption
! Column heading 1 !! Column heading 2 !! Column heading 3
|-
! Row heading 1
| Cell 2 || Cell 3
|-
! Row heading A
|Cell B
|Cell C
|}
The final table would display like this:
The table's caption Column heading 1 Column heading 2 Column heading 3 Row heading 1 Cell 2 Cell 3 Row heading A Cell B Cell C
The table parameters and cell parameters are the same as in HTML, see [1] and Table (HTML). However, the thead
, tbody
, tfoot
, colgroup
, and col
elements are currently not supported in MediaWiki.
A table can be useful even if none of the cells have content. For example, the background colors of cells can be changed with cell parameters, making the table into a diagram. An "image" in the form of a table is much more convenient to edit than an uploaded image.
Each row must have the same number of cells as the other rows, so that the number of columns in the table remains consistent. For empty cells, use the non-breaking space
as content to ensure that the cells are displayed. To show a visible pipe in a cell, use <nowiki>|</nowiki> or |.
With colspan and rowspan cells can span several columns or rows. However, this has the disadvantage that sorting does not work properly anymore.
Examples[edit]
Simple example[edit]
Both of these generate the same output. Choose a style based on the number of cells in each row and the total text inside each cell.
Wiki markup
{| | A | B |- | C | D |}
{| | A || B |- | C || D |}
What it looks like in your browser
A B C D
Multiplication table[edit]
Wiki markup
{| class="wikitable" style="text-align:center" |+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 |}
What it looks like in your browser (see: w:Help:User style)
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
Color; scope of parameters[edit]
See also: Wiki color formatting help
Two ways of specifying color of text and background for a single cell are as follows. The first form is preferred:
Wiki markup
{| | style="background:red; color:white" | abc | def | bgcolor="red" | <span style="color:white"> ghi </span> | jkl |}
What it looks like in your browser
abc def ghi jkl
Note: The bgcolor
is deprecated.
Like other parameters, colors can also be specified for a whole row or the whole table; parameters for a row override the value for the table, and those for a cell override those for a row:
Wiki markup
{| style="background:yellow; color:green" |- | abc || def || ghi |- style="background:red; color:white" | jkl || mno || pqr |- | stu || style="background:silver" | vwx || yz |}
What it looks like in your browser
abc def ghi jkl mno pqr stu vwx yz
To make the table blend in with the background, use style="background:none"
or style="background:transparent"
. (Warning: style="background:inherit"
, does not work with some browsers, including IE6!)
See : style, background, list of colors, web colors
Width, height[edit]
The width and height of the whole table can be specified, as well as the height of a row. To specify the width of a column one can specify the width of an arbitrary cell in it. If the width is not specified for all columns, and/or the height is not specified for all rows, then there is some ambiguity, and the result depends on the browser.
Wiki markup
{| style="width:75%; height:200px" border="1" |- | abc || def || ghi |- style="height:100px" | jkl || style="width:200px" |mno || pqr |- | stu || vwx || yz |}
What it looks like in your browser
abc def ghi jkl mno pqr stu vwx yz
Note that style="
inline CSS"
has no effect with some browsers. If compatibility is important, equivalent older constructs like width="75%"
should work on more browsers.
Setting your column widths[edit]
If you wish to force column widths to your own requirements, rather than accepting the width of the widest text element in a column's cells, then follow this example. Note that wrap-around of text is forced.
{| border="1" cellpadding="2" !width="50"|Name !width="225"|Effect !width="225"|Games Found In |- |Poké Ball || Regular Poké Ball || All Versions |- |Great Ball || Better than a Poké Ball || All Versions |}
Name Effect Games Found In Poké Ball Regular Poké Ball All Versions Great Ball Better than a Poké Ball All Versions
To set column widths in a table without headers, specify the width in the first cell for each column, like this:
{| border="1" cellpadding="2" |- |width="100pt"|This column is 100 points wide |width="200pt"|This column is 200 points wide |width="300pt"|This column is 300 points wide |- |blah || blah || blah |}
This column is 100 points wide This column is 200 points wide This column is 300 points wide blah blah blah
One application of setting the widths is aligning columns of consecutive tables:
Country | Capital |
---|---|
The Netherlands | Amsterdam |
Country | Capital |
---|---|
France | Paris |
Vertical alignment[edit]
By default data in tables is vertically centrally aligned, which results in odd-looking layouts like this:
Row heading A longer piece of text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. A shorter piece of text. Row heading A longer piece of text.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. A shorter piece of text.
To fix this, apply the valign="top" attribute to the rows (unfortunately it seems to be necessary to apply this individually to every single row). For example:
{| border="1" cellpadding="2" |-valign="top" |width="10%"|'''Row heading''' |width="70%"|A longer piece of text. Lorem ipsum... |width="20%"|A shorter piece of text. |-valign="top" |'''Row heading''' |A longer piece of text. Lorem ipsum... |A shorter piece of text. |}
Row heading A longer piece of text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. A shorter piece of text. Row heading A longer piece of text.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. A shorter piece of text.
Positioning[edit]
One can position the table itself, and all contents in a row, and contents in a cell, but not with a single parameter for all contents in the table, see m:Template talk:Table demo. Do not, under any circumstances, use "float" to position a table. It will break page rendering at large font sizes.
Mélange[edit]
Here's a more advanced example, showing some more options available for making up tables. Note, however, that with use of the colspan and rowspan attributes, sorting does not work properly anymore.
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.
Wiki markup
{| border="1" cellpadding="5" cellspacing="0" align="center" |+'''An example table''' |- ! style="background:#efefef;" | First header ! colspan="2" style="background:#ffdead;" | Second header |- | upper left | | rowspan=2 style="border-bottom:3px solid gray;" valign="top" |right side |- | style="border-bottom:3px solid gray;" | lower left | style="border-bottom:3px solid gray;" | lower middle |- | colspan="3" align="center" | {| border="0" |+''A table in a table'' |- | align="center" width="150px" | <!--[[-->Image:Wiki.png<!--]]--> | align="center" width="150px" | <!--[[-->Image:Wiki.png<!--]]--> |- | 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 Wikimedia logos |} |}
What it looks like in your browser
An example table First header Second header upper left right side
lower left lower middle
A table in a table File:Wiki.png File:Wiki.png Two Wikimedia logos
Floating table[edit]
Wiki markup
This paragraph is before the table. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation... {| align="right" border="1" | Col 1, row 1 |rowspan="2"| Col 2, row 1 (and 2) | Col 3, row 1 |- | Col 1, row 2 | Col 3, row 2 |} Note the floating table to the right. This paragraph is after the table. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation...
What it looks like in your browser
This paragraph is before the table. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation...
Col 1, row 1 Col 2, row 1 (and 2) Col 3, row 1 Col 1, row 2 Col 3, row 2 Note the floating table to the right.
This paragraph is after the table. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation...
Nested tables[edit]
Five different (blue) tables are shown nested inside the cells of a table. Automatically the two tables |A| and |B|B| are vertically aligned instead of the usual side by side of text characters in a cell. "float" is used to fix each of tables |C| and |D| to their own position within one cell of the table. This may be used for charts and schemes. Nested tables must start on a new line.
Wiki markup
{| border="1"
| α
| align="center" | cell2
{| border="2" style="background:#ABCDEF;" <!-- The nested table must be on a new line -->
| NESTED
|-
| TABLE
|}
| valign="bottom" | the original table again
| style="width:100px;" |
{| border="2" style="background:#ABCDEF;;"
| A
|}
{| border="2" style="background:#ABCDEF;"
| B || B
|}
| style="width:50px;" |
{| border="2" style="background:#ABCDEF; float:left;"
| C
|}
{| border="2" style="background:#ABCDEF; float:right;"
| D
|}
|}
What it looks like in your browser
α cell2
NESTED TABLE the original table again
A
B B
C
D
Combined use of COLSPAN and ROWSPAN[edit]
Wiki markup
{| border="1" cellpadding="5" cellspacing="0" |- | Column 1 || Column 2 || Column 3 |- | rowspan="2"| A | colspan="2" align="center"| B |- | C <!-- column 1 occupied by cell A --> | D |- | E | rowspan="2" colspan="2" align="center"| F |- | G <!-- column 2+3 occupied by cell F --> |- | colspan="3" align="center"| H |}
What it looks like in your browser
Column 1 Column 2 Column 3 A B C D E F G H
Note that using rowspan="2"
for cell G combined with rowspan="3"
for cell F to get another row below G and F won't work, because all (implicit) cells would be empty.
Likewise complete columns are not displayed if all their cells are empty. Borders between non-empty and empty cells might be also not displayed (depending on the browser), use
to fill an empty cell with dummy content.
Centering tables[edit]
Centered tables can be achieved, but they will not "float"; that is to say, no text will appear to either side. The trick is {| style="margin: 1em auto 1em auto"
Wiki markup
{| class="wikitable" style="margin: 1em auto 1em auto" |+ '''Cells left-aligned, table centered''' ! Duis || aute || irure |- | dolor || in reprehenderit || in voluptate velit |- | esse cillum dolore || eu fugiat nulla || pariatur. |}
What it looks like in your browser
Cells left-aligned, table centered Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Setting parameters[edit]
At the start of a cell, add your parameter followed by a single pipe. For example width="300"| will set that cell to a width of 300 pixels. To set more than one parameter, leave a space between each one.
Wiki markup
{| style="color:white" |- | bgcolor="red"|cell1 || width="300" bgcolor="blue"|cell2 || bgcolor="green"|cell3 |}
What it looks like in your browser
cell1 cell2 cell3
Decimal point alignment[edit]
A simple and reliable way to achieve decimal point alignment is to use [[Template:0]]</nowiki, assuming it has been defined along the following lines: <nowiki><span style="visibility:hidden;color:transparent;">{{{1|0}}}</span>
See w:Template:0 for further details.
Another method to get columns of numbers aligned at the decimal point is as follows:
Wiki markup
{| cellpadding="0" cellspacing="0" |align="right"| 432 || .1 |- |align="right"| 43 || .21 |- |align="right"| 4 || .321 |}
What it looks like in your browser
432 .1 43 .21 4 .321
If the column of numbers appears in a table with cell padding or cell spacing, one can still align the decimal points without an unsightly gap in the middle. Embed a table in each number's cell and specify its column widths. Make the embedded tables' column widths the same for each cell in the column. (If decimal points are still misaligned using this method, the main table's column may be too narrow. Add a parameter to increase the column's width.)
Wiki markup
{|border="1" cellpadding="4" cellspacing="2" width="50%" | {|cellpadding="0" cellspacing="0" width="100%" |align="right" width="50%"| 432 ||width="50%"| .1 |} |- | {|cellpadding="0" cellspacing="0" width="100%" |align="right" width="50%"| 43 ||width="50%"| .21 |} |- | {|cellpadding="0" cellspacing="0" width="100%" |align="right" width="50%"| 4 ||width="50%"| .321 |} |}
What it looks like in your browser
432 .1
43 .21
4 .321
In simple cases one can dispense with the table feature and simply start the lines with a space, and put spaces to position the numbers:
432.1 43.21 4.321
Style classes[edit]
(could more than likely remove this code, not that much would be useful for the general wiki user)
- See also w:Help:User style.
In the first line of table code, after the "{|", instead of specifying a style directly one can also specify a CSS class. The style for this class can be specified in various ways:
- in the software itself, per skin (for example the class sortable, used at wikibits.js)
- collectively for all users of one wiki in MediaWiki:Common.css (for example, on this and some other projects there is the class wikitable)
- separately per skin in MediaWiki:Monobook.css etc.
- individually on one wiki in a user subpage
- individually, but jointly for tables of the class concerned on all web pages, on the local computer of the user.
Instead of remembering table parameters, you just include an appropriate style class after the {|
. This helps keep table formatting consistent, and can allow a single change to the class to fix a problem or enhance the look of all the tables that are using it at once. For instance, this:
{| border="1" cellpadding="2" |+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 |} |
| |||||||||||||||||||||||||
becomes this: | ||||||||||||||||||||||||||
{| class="wikitable" |+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 |} |
|
simply by replacing inline CSS for the table by class="wikitable"
. This is because the wikitable class in MediaWiki:Common.css contains a number of table.wikitable CSS style rules. These are all applied at once when you mark a table with the class. You can then add additional style rules if desired. These override the class's rules, allowing you to use the class style as a base and build up on it:
Wiki markup
{| class="wikitable" style="font-style:italic; font-size:120%; border:3px dashed red;" |+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 |}
What it looks like in your browser
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
Notice that the table retains the gray background of the wikitable class, and the headers are still bold and centered. But now the text formatting has been overridden by the local style statement; all of the text in the table has been made italic and 120% normal size, and the wikitable border has been replaced by the red dashed border.
Of course this works only for browsers supporting inline CSS, if it's important use XHTML markup like <big>
instead of "font-size:120%", or Wiki markup like ''text''
instead of "font-style:italic".
Sorting[edit]
Tables can be made sortable by adding class="sortable"
; for details see w:Help:Sorting. Since this can be very useful, it is wise to keep the possibilities and limitations of this feature in mind when designing a table. For example:
- Do not divide a table into sections by subheaders spanning several rows. Instead, an extra column can be made showing the content of these headers on each row, in a short form.
- Do not have elements spanning several columns; instead, again, repeat the content on each row, in a short form.
- In a column of numbers, do not put text such as "ca." in front of a number—it will sort like zero. Do not put text after the number, and do not put a range of numbers (it does not affect the sorting position for numeric sorting mode, and in the case of a range, the first number determines the position, but if, possibly after sorting this or another column, the element is at the top, it will induce alphabetic sorting mode). Instead, put these texts in a separate column. Alternatively, for the greatest flexibility, alphabetic sorting mode with hidden sortkeys can be used.
A long form of abbreviated content can be put as legend outside the table.
Wiki markup
{| class="wikitable sortable" |+Sortable table |- ! Alphabetic !! Numeric !! Date !! class="unsortable" | Unsortable |- | d || 2 || 2008-11-24 || This |- | b || 8 || 2004-03-01 || column |- | a || 6 || 1979-07-23 || cannot |- | c || 4 || 1492-12-08 || be |- | e || 0 || 1601-08-13 || sorted. |}
What it looks like in your browser
Sortable table Alphabetic Numeric Date Unsortable d 2 2008-11-24 This b 8 2004-03-01 column a 6 1979-07-23 cannot c 4 1492-12-08 be e 0 1601-08-13 sorted.
Row template[edit]
Regardless of whether wikitable format or HTML is used, the wikitext of the rows within a table, and sometimes even within a collection of tables, has much in common, e.g.:
- the basic code for a table row
- code for color, alignment, and sorting mode
- fixed texts such as units
- special formats for sorting
In that case it can be useful to create a template that produces the syntax for a table row, with the data as parameters. This can have many advantages:
- easily changing the order of columns, or removing a column
- easily adding a new column if many elements of the new column are left blank (if the column is inserted and the existing fields are unnamed, use a named parameter for the new field to avoid adding blank parameter values to many template calls)
- computing fields from other fields, e.g. population density from population and area
- duplicating content and providing span tags with "display:none" for the purpose of having one format for sorting and another for display
- easy specification of a format for a whole column, such as color and alignment
Conditional table row[edit]
(would possibly remove/not include this section from GWW form)
A pipe character for a table row may be desired as part of a parameter value in the call of a template or parser function (in particular, it can be in code made optional using w:ParserFunctions). However, expansion of templates and parser functions happens before interpretation of table syntax. This causes a pipe character in a parameter value to be interpreted as a separator between parameter definitions.
If one tries to use as conditional code for a conditional row "{{!}}-<newline>{{!}}text<newline>" the problem is that the last <newline> is ignored:
a{{#if:1|b }}c
gives "abc".
Thus, depending on whether there is a <newline> after the condition, we could have a newline too many or too few.
This is solved by using the technique of Help:Newlines and spaces#Spaces and/or newlines as value of an unnamed parameter:
Other table syntax[edit]
(would possibly remove/not include this section from GWW form)
Other types of table syntax that MediaWiki supports:
- XHTML
- HTML & wiki-<td> syntax (Do not use)
All three are supported by MediaWiki and create (currently) valid HTML output, but the pipe syntax is the simplest. Also, HTML & wiki-<td> syntax (i.e., unclosed <td> and <tr> tags) will not necessarily remain browser-supported in the upcoming future, especially on handheld internet-accessible devices.
See also Table (HTML), HTML element#Tables. Note however that the thead
, tbody
, tfoot
, colgroup
, and col
elements are currently not supported in MediaWiki.
Comparison of table syntax[edit]
XHTML | HTML & Wiki-td | Wiki-pipe | |||||||
---|---|---|---|---|---|---|---|---|---|
Table | <table></table> | <table></table> | {| |} | ||||||
Caption | <caption>caption</caption> | <caption>caption</caption> | |+ caption | ||||||
Row | <tr></tr> | <tr> | |- | ||||||
Data cell |
<td>cell1</td> |
<td>cell1 |
| cell1 | cell2 | ||||||
Data cell | <td>cell1</td> <td>cell2</td> <td>cell3</td> | <td>cell1 <td>cell2 <td>cell3 | | cell1 || cell2 || cell3 | ||||||
Header cell | <th>heading</th> | <th>heading | ! heading | ||||||
Sample table |
| ||||||||
<table> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>3</td> <td>4</td> </tr> </table> | <table> <tr> <td> 1 <td> 2 <tr> <td> 3 <td> 4 </table> | {| | 1 || 2 |- | 3 || 4 |} | |||||||
Sample table |
| ||||||||
<table> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> </tr> </table> | <table> <tr> <td> 1 <td> 2 <tr> <td> 3 <td> 4 <tr> <td> 5 <td> 6 </table> | {| | 1 || 2 |- | 3 || 4 |- | 5 || 6 |} | |||||||
Pros |
|
|
| ||||||
Cons |
|
|
| ||||||
XHTML | HTML & Wiki-td | Wiki-pipe |
See also Template:For.
Pipe syntax in terms of the HTML produced[edit]
(would remove/not include this section from GWW form)
The pipe syntax, developed by Magnus Manske, substitutes pipes (|) for HTML. There is an on-line script which converts html tables to pipe syntax tables.
The pipes must start at the beginning of a new line, except when separating parameters from content or when using ||
to separate cells on a single line. The parameters are optional.
Tables[edit]
A table is defined by {| ''params'' |} which equals <table ''params''>Insert non-formatted text here </table>
Rows[edit]
<tr> tags will be generated automatically for the first row. To start a new row, use
|-
which results in
<tr>
Parameters can be added like this:
|- params
which results in
<tr params>
Note:
- <tr> tags will be automatically opened at the first <td> equivalent
- <tr> tags will be automatically closed at <tr> and </table> equivalents
Cells[edit]
Cells are generated either like this:
|cell1 |cell2 |cell3
or like this:
|cell1||cell2||cell3
which both equal
<td>cell1</td><td>cell2</td><td>cell3</td>
so "||" equals "newline" + "|"
Parameters in cells can be used like this:
|params|cell1||params|cell2||params|cell3
which will result in
<td params>cell1</td> <td params>cell2</td> <td params>cell3</td>
Headers[edit]
Functions the same way as TD, except "!" is used instead of the opening "|". "!!" can be used instead of "||". Parameters still use "|", though! Example:
!params|cell1
Captions[edit]
A <caption> tag is created by
|+ Caption
which generates
<caption>Caption</caption>
You can also use parameters:
|+ params|Caption
which will generate
<caption params>Caption</caption>
Displaying the table code which generates a table[edit]
(could more than likely remove this code, this is more for the people who are making how-to pages for others, and not that much would be happening for the general wiki user)
The code for a simple wiki markup table inside a Code box can be seen below.
{| border="5" cellspacing="5" cellpadding="2" | style="text-align: center;" | <!--[[-->Image:gnome-system.png<!--]]--> |- ! Computer |- | Processor Speed: 1.8 GHz |}
Above code produces/displays the table below:
File:Gnome-system.png |
Computer |
---|
Processor Speed: 1.8 GHz |
Below code, generated and displayed the above table's Code box code itself, on the screen and web page, inside a blue colored dashed bordered rectangular box.
<pre> {| border="5" cellspacing="5" cellpadding="2" | style="text-align: center;" | [[Image:gnome-system.png]] |- ! Computer |- | Processor Speed: 1.8 GHz |} </pre> |
Note that, HTML tag <pre> was used to achieve displaying the above codes and the Code box.
Other alternatives to display table code[edit]
(could more than likely remove this code, this is more for the people who are making how-to pages for others, and not that much would be happening for the general wiki user)
In most cases, when a code line is longer than the web browser window's width, then a scrolling bar appears at bottom, to let the viewer slide to the right side (and also left side) to see the rest of the codes, because, the use of <pre> tag causes the code line to remain intact, unless an EOL (CR/LF) hidden character is reached in that text line. But having to slide or scroll to the right or left for viewing the full codes is often not comfortable to many readers. To solve such problem, using the <p>, <tt> and <br /> HTML tags, are better than using the <pre> tag, as those will limit the length of a line of code according the available space in the web browser's window and therefor will not result in the need to move the scroll-bar right (or left) for viewing. By placing the codes inside the <tt>...</tt> HTML tags, codes are displayed with a fixed width text/font, (like the <pre> tag uses) for easier reading. HTML tag <br /> is used to display (or bring) next line of codes, starting from the next line. HTML tag <p> along with its CSS style properties, is used to create the blue colored dashed bordered rectangular box (Code box) around the codes, (like the HTML <pre> tag, which gets these properties from the main.css stylesheet file).
An example of table code with a long line is:
{| border="5" cellspacing="5" cellpadding="2"
| style="text-align: center;" | [[Image:gnome-system.png]]
|-
! Computer
|-
| style="color: yellow; background-color: green;" | Processor Speed: <span style="color: white;"> 1.8 GHz </span>
|}
producing the below table:
Image:gnome-system.png |
Computer |
---|
Processor Speed: 1.8 GHz |
Code box above the table has the auto line wrapping feature enabled. Note the long line (the sixth line from top) inside the codes, which is wrapped inside the Code box. This Code box and the codes, can be displayed by using below codes in the edit box.
<p style="padding: 1em; border: 1px dashed #2f6fab; color: Black; background-color: #f9f9f9; line-height: 1.1em;"> <tt>
<nowiki>{|</nowiki> border="5" cellspacing="5" cellpadding="2" <br />
| style="text-align: center;" | <nowiki>[[</nowiki>Image:gnome-system.png]] <br />
|- <br />
! Computer <br />
|- <br />
| style="color: yellow; background-color: green;" | Processor Speed: <nowiki><span style="color: white;"></nowiki> 1.8 GHz <nowiki></span></nowiki> <br />
<nowiki>|}</nowiki> <br />
</tt> </p>
See the above codes, note that, <nowiki>...</nowiki> tags were used to disable wiki markup codes for beginning a table ({|), ending a table (|}), start of an image displaying ([[), or a hyperlink, etc. All wiki & HTML markup codes need to be disabled by enclosing them inside the <nowiki>...</nowiki> tags. If these codes were to be displayed inside another table, then, each | (pipe) & ! (Exclamation mark) symbol also needed to be enclosed inside the <nowiki> tags. Note that, the longer line is automatically wrapped according to the width of the web browser's window, inside the Code box.
Alternatively, we can replace each | (pipe symbol) character with | (HTML decimal entity code), replace each ! (exclamation mark) with ! code, replace { (beginning curly/second bracket) with { and we may replace } (closing curly/second bracket) with } code. Also replace the < (less than sign, or beginning angle bracket) with < numeric entity code or, replace it with < (HTML symbol entity code). For more on HTML decimal or hexadecimal numeric entity codes, please see w:Windows Alt codes. To display the wiki image markup code, we should replace the [ (beginning square/third bracket) with [ and we may replace ] (closing square/third bracket) with ]. When we are replacing characters with their numeric enitity codes, we are actually disabling their normal functionality, so we can display them on the web page(s).
By using the numeric entity codes, mentioned in the above paragraph, below codes can display the above Code box in another alternative (better) way. Note that, the longer line is automatically wrapped, without exceeding the browser window's width, inside the below Code box. |
|
<p style="padding: 1em; border: 1px dashed #2f6fab; color: Black; background-color: #f9f9f9; line-height: 1.1em;"> <tt>
{| border="5" cellspacing="5" cellpadding="2" <br />
| style="text-align: center;" | [[Image:gnome-system.png]] <br />
|- <br />
! Computer <br />
|- <br />
| style="color: yellow; background-color: green;" | Processor Speed: <span style="color: red;"> 1.8 GHz </span> <br />
|} <br />
</tt> </p>
See also disabling wikitext interpretation and/or reformatting.
Square monitors[edit]
(would remove/not include this section from GWW form)
To format for a square monitor or window, use a tape measure. Determine the height of your rectangular screen. Using that figure measure under the screen to determine the width your monitor’s screen would be if it were square. Mark that location using ink or tape under the screen. Drag the side of your browser’s window to that location so the window is square based on accurate measurements. Square monitors and reading windows are not able to contain tables and galleries made for rectangular and wide screens. When a table or gallery is wider than the monitor, it makes every line of text wider than the screen as well. The px amounts of the following gallery were determined after measuring the window to make sure it was square:
Type this:
<center>
{| border="0" style="background:transparent;"
|-
|
[[Image:Some_window_blinds.JPG|192px x 155px|thumb|left|Various window shades]]
||
[[Image:Vert-blinds-2145-rs.jpg|192px x 170px|thumb|left|Vertical blinds]]
||
[[Image:2008-08-24 Carpet array.jpg|192px x 155px|thumb|left|This is not a blind]]
|}
</center>
<br />
<center>
{| border="0" style="background:transparent;"
|-
|
[[Image:Vorhang.jpg|192px x 155px|thumb|left|Solid shade]]
||
[[Image:Jalousie-1.jpg|328px x 55px|thumb|left|Horizonal blinds]]
|}
</center>
<br />
<center>
{| border="0" style="background:transparent;"
|-
|
[[Image:Some_window_blinds.JPG|225px|thumb|left|Shade, shutters; vertical & horizontal blinds.]]
||
[[Image:Miniblinds detail of mechanism.jpg|418px|thumb|left|Detail of turning rod (blind stick) attachment on miniblinds]]
|}
</center>
For this:
Image:Some_window_blinds.JPG |
Image:Vert-blinds-2145-rs.jpg |
Image:Gardine.jpg |
Image:Vorhang.jpg |
Image:Jalousie-1.jpg |
Image:Some_window_blinds.JPG |
Image:Miniblinds detail of mechanism.jpg |
Viewing tables in email and web pages outside Wikipedia[edit]
(would remove/not include this section from GWW form)
Tables are an essential part of presenting information in an easily understandable way. Everything on Wikipedia can be copied elsewhere, and it is encouraged. But Wikipedia tables oftentimes lose their borders when pasted into web pages, blogs, or email.
The Wikipedia table button produces this:
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 |
Note the borders around all the cells, and the whole table. Copy and paste the table into your email, and the borders disappear. This makes the table look something like this below. It is much less understandable.
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 is easily fixed. If you want and expect your table to be passed around in email, blogs, and other web pages, then add
- border="1"
somewhere in the first line of your chart wikicode. For example;
{| class="wikitable" border="1" |- ! 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 |} |
The table will look the same on the Wikipedia page, but it will now also have borders when copied into email, blogs, and other web pages. Bloggers and webmasters will not have to add CSS code in order to see the chart in a format with basic borders.
See also[edit]
- m:simplified table syntax
- m:wiki markup tables
- m:table background colors
- w:en:User:Dcljr/Tables
- w:Table (HTML)
- Help:Template#A_parameter_value_containing_a_pipe_character
- Category:Commons charts and graphs - resources.
- w:Category:Table and column templates
External links[edit]
(would remove/not include this section from GWW form as most of these reference the Excel to wikitable section)
- de:Wikipedia:Helferlein/VBA-Macro for EXCEL tableconversion published in German-Wikipediaproject (english instructions included)
- HTML tables to wiki converter at cnic.org
- csv2wp - converts comma-separated values (CSV) format to pipe syntax. You may use this to import tables from Excel etc. (more information)
- HTML tables to wiki converter at uni-bonn.de
- HTML tables to wiki converter at diberri.dyndns.org
- pywikipediabot (can convert HTML tables to wiki)
- HTML-WikiConverter. Various versions and languages.