![FairMormon Logo](https://www.fairlatterdaysaints.org/wp-content/uploads/2021/01/2021_fair_logo_primary.png)
FAIR is a non-profit organization dedicated to providing well-documented answers to criticisms of the doctrine, practice, and history of The Church of Jesus Christ of Latter-day Saints.
Rivi 1: | Rivi 1: | ||
− | + | This page gives you information about syntax to build wiki-tables. | |
− | * <a | + | == Pipe syntax tutorial == |
+ | |||
+ | Although HTML table syntax also works, special [[wikicode]] can be used as a shortcut to create a table. The pipe ([[w:vertical bar|vertical bar]]) codes function exactly the same as [[w:HTML table|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 <code>'''{|'''</code> to begin a table, and <code>'''|}'''</code> to end it. Each one needs to be on its own line: | ||
+ | <span style="font-weight:bold; color:red"><nowiki>{|</nowiki></span> | ||
+ | ''table code goes here'' | ||
+ | <span style="font-weight:bold; color:red"><nowiki>|}</nowiki></span> | ||
+ | * An optional '''table [[caption]]''' is included with a line starting with a vertical bar and plus sign "<code>'''|+'''</code>" and the caption after it: | ||
+ | <nowiki>{|</nowiki> | ||
+ | <span style="font-weight:bold; color:red"><nowiki>|+</nowiki> ''caption''</span> | ||
+ | ''table code goes here'' | ||
+ | <nowiki>|}</nowiki> | ||
+ | * To start a new '''table [[row]]''', type a vertical bar and a [[w:dash|dash]] on its own line: "<code>'''|-'''</code>". The codes for the cells in that row will start on the next line. | ||
+ | <nowiki>{|</nowiki> | ||
+ | <nowiki>|+</nowiki> The table's caption | ||
+ | <span style="font-weight:bold; color:red"><nowiki>|-</nowiki></span> | ||
+ | ''cell code goes here'' | ||
+ | <span style="font-weight:bold; color:red"><nowiki>|-</nowiki></span> | ||
+ | ''cell code goes here'' | ||
+ | <nowiki>|}</nowiki> | ||
+ | * Type the codes for each ''table [[w:cell|cell]]'' in the next row, starting with a bar: | ||
+ | <nowiki>{|</nowiki> | ||
+ | <nowiki>|+</nowiki> The table's caption | ||
+ | <nowiki>|-</nowiki> | ||
+ | <span style="font-weight:bold; color:red">|</span> ''cell codes go here'' | ||
+ | <nowiki>|-</nowiki> | ||
+ | <span style="font-weight:bold; color:red">|</span> ''cells in the next row go here'' | ||
+ | <span style="font-weight:bold; color:red">|</span> ''more cells in the same row here'' | ||
+ | <nowiki>|}</nowiki> | ||
+ | * 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: | ||
+ | <nowiki>{|</nowiki> | ||
+ | <nowiki>|+</nowiki> The table's caption | ||
+ | <nowiki>|-</nowiki> | ||
+ | <span style="font-weight:bold; color:red">|Cell 1 || Cell 2 || Cell 3</span> | ||
+ | <nowiki>|-</nowiki> | ||
+ | <span style="font-weight:bold; color:red">|Cell A </span> | ||
+ | <span style="font-weight:bold; color:red">|Cell B</span> | ||
+ | <span style="font-weight:bold; color:red">|Cell C</span> | ||
+ | <nowiki>|}</nowiki> | ||
+ | * a row of '''[[w:column heading|column heading]]s''' is identified by using "!" instead of "|", and using "!!" instead of "||". Header cells typically render differently than regular cells, depending on the browser. They are often rendered in a bold font and centered. | ||
+ | <nowiki>{|</nowiki> | ||
+ | <nowiki>|+</nowiki> The table's caption | ||
+ | <span style="font-weight:bold; color:red">! Column heading 1 !! Column heading 2 !! Column heading 3</span> | ||
+ | <nowiki>|-</nowiki> | ||
+ | |Cell 1 || Cell 2 || Cell 3 | ||
+ | <nowiki>|-</nowiki> | ||
+ | |Cell A | ||
+ | |Cell B | ||
+ | |Cell C | ||
+ | <nowiki>|}</nowiki> | ||
+ | * the first cell of a row is identified as '''[[w:row heading|row heading]]''' by starting the line with "!" instead of "|", and starting subsequent data cells on a new line. | ||
+ | <nowiki>{|</nowiki> | ||
+ | <nowiki>|+</nowiki> The table's caption | ||
+ | ! Column heading 1 !! Column heading 2 !! Column heading 3 | ||
+ | <nowiki>|-</nowiki> | ||
+ | <span style="font-weight:bold; color:red">! Row heading 1</span> | ||
+ | | Cell 2 || Cell 3 | ||
+ | <nowiki>|-</nowiki> | ||
+ | <span style="font-weight:bold; color:red">! Row heading A</span> | ||
+ | |Cell B | ||
+ | |Cell C | ||
+ | <nowiki>|}</nowiki> | ||
+ | * Optional '''parameters''' can modify the behavior of cells, rows, or the entire table. For instance, a border could be added to the table: | ||
+ | <nowiki>{|</nowiki> <span style="font-weight:bold; color:red">border="1"</span> | ||
+ | <nowiki>|+</nowiki> The table's caption | ||
+ | ! Column heading 1 !! Column heading 2 !! Column heading 3 | ||
+ | <nowiki>|-</nowiki> | ||
+ | ! Row heading 1 | ||
+ | | Cell 2 || Cell 3 | ||
+ | <nowiki>|-</nowiki> | ||
+ | ! Row heading A | ||
+ | |Cell B | ||
+ | |Cell C | ||
+ | <nowiki>|}</nowiki> | ||
+ | The final table would display like this: | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| 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 | ||
+ | |} | ||
+ | </blockquote> | ||
+ | The table parameters and cell parameters are the same as in [[w:HTML|HTML]], see [http://www.w3.org/TR/html401/struct/tables.html#edef-TABLE] and [[w:Table (HTML)|Table (HTML)]]. However, the <code>thead</code>, <code>tbody</code>, <code>tfoot</code>, <code>colgroup</code>, and <code>col</code> elements are currently not [[Help:HTML in wikitext#Permitted_HTML|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, like [[m:Template talk:Square 8x8 pentomino example]]. 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 (unless there are cells which span several columns or rows, see colspan and rowspan in Mélange example below). For empty cells, use the non-breaking space <code>&nbsp;</code> as content to ensure that the cells are displayed. | ||
+ | To add a visible | into a table use <nowiki>|</nowiki> or &#124; | ||
+ | |||
+ | ==Examples== | ||
+ | |||
+ | === Simple example === | ||
+ | Both of these generate the same output. Choose a style based on the amount of cells in each row and the total text inside each cell. | ||
+ | |||
+ | '''Wiki markup''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| | ||
+ | | Cell 1, row 1 | ||
+ | | Cell 2, row 1 | ||
+ | |- | ||
+ | | Cell 1, row 2 | ||
+ | | Cell 2, row 2 | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| | ||
+ | | Cell 1, row 1 || Cell 2, row 1 | ||
+ | |- | ||
+ | | Cell 1, row 2 || Cell 2, row 2 | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| | ||
+ | | Cell 1, row 1 | ||
+ | | Cell 2, row 1 | ||
+ | |- | ||
+ | | Cell 1, row 2 | ||
+ | | Cell 2, row 2 | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | ===Multiplication table=== | ||
+ | |||
+ | '''Wiki markup''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| class="wikitable" style="text-align:center" | ||
+ | |+Multiplication table | ||
+ | |- | ||
+ | ! &times; !! 1 !! 2 !! 3 | ||
+ | |- | ||
+ | ! 1 | ||
+ | | 1 || 2 || 3 | ||
+ | |- | ||
+ | ! 2 | ||
+ | | 2 || 4 || 6 | ||
+ | |- | ||
+ | ! 3 | ||
+ | | 3 || 6 || 9 | ||
+ | |- | ||
+ | ! 4 | ||
+ | | 4 || 8 || 12 | ||
+ | |- | ||
+ | ! 5 | ||
+ | | 5 || 10 || 15 | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| 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 | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | ===Color; scope of parameters=== | ||
+ | |||
+ | Two ways of specifying color of text and background for a single cell are as follows. The first form is preferred: | ||
+ | |||
+ | '''Wiki markup''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| | ||
+ | | style="background:red; color:white" | abc | ||
+ | | def | ||
+ | | bgcolor="red" | <font color="white"> ghi </font> | ||
+ | | jkl | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| | ||
+ | | style="background:red; color:white" | abc | ||
+ | | def | ||
+ | | bgcolor="red" | <font color="white"> ghi </font> | ||
+ | | jkl | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | 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''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| style="background:yellow; color:green" | ||
+ | |- | ||
+ | | abc || def || ghi | ||
+ | |- style="background:red; color:white" | ||
+ | | jkl || mno || pqr | ||
+ | |- | ||
+ | | stu || style="background:silver" | vwx || yz | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| style="background:yellow; color:green" | ||
+ | |- | ||
+ | | abc || def || ghi | ||
+ | |- style="background:red; color:white" | ||
+ | | jkl || mno || pqr | ||
+ | |- | ||
+ | | stu || style="background:silver" | vwx || yz | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | To make the table blend in with the background, use <code>style="background:none"</code>. (Warning: <code>style="background:inherit"</code>, does not work with some browsers, including IE6!) | ||
+ | |||
+ | ===Width, height=== | ||
+ | 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''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| style="width:75%; height:200px" border="1" | ||
+ | |- | ||
+ | | abc || def || ghi | ||
+ | |- style="height:100px" | ||
+ | | jkl || style="width:200px" |mno || pqr | ||
+ | |- | ||
+ | | stu || vwx || yz | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| style="width:75%; height:200px" border="1" | ||
+ | |- | ||
+ | | abc || def || ghi | ||
+ | |- style="height:100px" | ||
+ | | jkl || style="width:200px" |mno || pqr | ||
+ | |- | ||
+ | | stu || vwx || yz | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | Note that <code>style="</code>inline CSS<code>"</code> has no effect with some browsers. If it's important equivalent older constructs like <code>width="75%"</code> should work on more browsers. | ||
+ | |||
+ | ====Setting your column widths==== | ||
+ | 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. | ||
+ | |||
+ | <blockquote style="background: white; border: 1px solid black; padding: 1em;"><pre><nowiki> | ||
+ | {| border="1" cellpadding="2" | ||
+ | !width="50"|Name | ||
+ | !width="225"|Effect | ||
+ | !width="225"|Games Found In | ||
+ | |- | ||
+ | |Pokeball || Regular Pokeball || All Versions | ||
+ | |- | ||
+ | |Great Ball || Better than a Pokeball || All Versions | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | <blockquote style="background: white; border: 1px solid black; padding: 1em;"> | ||
+ | {| border="1" cellpadding="2" | ||
+ | !width="50"|Name | ||
+ | !width="225"|Effect | ||
+ | !width="225"|Games Found In | ||
+ | |- | ||
+ | |Pokeball || Regular Pokeball || All Versions | ||
+ | |- | ||
+ | |Great Ball || Better than a Pokeball || All Versions | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | ===Positioning=== | ||
+ | One can position the table itself, and all contents in a row, and contents in a cell, but not with a single parameter 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=== | ||
+ | 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. | ||
+ | |||
+ | '''Wiki markup''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| 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 grey;" valign="top" | | ||
+ | right side | ||
+ | |- | ||
+ | | style="border-bottom:3px solid grey;" | lower left | ||
+ | | style="border-bottom:3px solid grey;" | 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 | ||
+ | |} | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| border="1" cellpadding="1" 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 grey;" valign="top" | | ||
+ | right side | ||
+ | |- | ||
+ | | style="border-bottom:3px solid grey;" | lower left | ||
+ | | style="border-bottom:3px solid grey;" | 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 | ||
+ | |} | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | === Floating table === | ||
+ | '''Wiki markup''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | 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... | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | |||
+ | 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... | ||
+ | </blockquote>{{-}} | ||
+ | |||
+ | === Nested tables === | ||
+ | This shows one table (in blue) nested inside another table's cell2. ''Nested tables have to start on a new line.'' | ||
+ | |||
+ | '''Wiki markup''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><p style="border: 1px dashed #2f6fab; background-color: #f9f9f9;"><tt> | ||
+ | <nowiki>{|</nowiki> border="1"<br /> | ||
+ | | &alpha;<br /> | ||
+ | | align="center" | cell2<br /> | ||
+ | <span style="color: navy;"> | ||
+ | '''<nowiki>{|</nowiki> border="2" style="background-color:#ABCDEF;"'''<br /> | ||
+ | '''| NESTED'''<br /> | ||
+ | '''|-'''<br /> | ||
+ | '''| TABLE'''<br /> | ||
+ | '''<nowiki>|}</nowiki>'''<br /> | ||
+ | </span> | ||
+ | | valign="bottom" | the original table again<br /> | ||
+ | <nowiki>|}</nowiki> | ||
+ | </tt></p></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| border="1" | ||
+ | | α | ||
+ | | align="center" | cell2 | ||
+ | {| border="2" style="background-color:#ABCDEF;" | ||
+ | | NESTED | ||
+ | |- | ||
+ | | TABLE | ||
+ | |} | ||
+ | | valign="bottom" | the original table again | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | ===Combined use of COLSPAN and ROWSPAN=== | ||
+ | |||
+ | '''Wiki markup''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| 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 | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| 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 | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | Note that using <code>rowspan="2"</code> for cell '''G''' combined with <code>rowspan="3"</code> 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 <code>&nbsp;</code> to fill an empty cell with dummy content. | ||
+ | |||
+ | ===Centering tables=== | ||
+ | Centered tables can be achieved, but they will not "float"; that is to say, no text will appear to either side. The trick is <tt><nowiki>{| style="margin: 1em auto 1em auto"</nowiki></tt> | ||
+ | |||
+ | '''Wiki markup''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| 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. | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| 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. | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | ===Setting parameters=== | ||
+ | |||
+ | At the start of a cell, add your parameter followed by a single pipe. For example <tt>width="300"|</tt> will set that cell to a width of 300 pixels. To set more than one parameter, leave a space between each one. | ||
+ | |||
+ | '''Wiki markup''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| | ||
+ | |- | ||
+ | | bgcolor="red"|cell1 || width="300" bgcolor="blue"|cell2 || bgcolor="green"|cell3 | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| | ||
+ | |- | ||
+ | | bgcolor="red"|cell1 || width="300" bgcolor="blue"|cell2 || bgcolor="green"|cell3 | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | ===Decimal point alignment=== | ||
+ | |||
+ | A method to get columns of numbers aligned at the decimal point is as follows: | ||
+ | |||
+ | '''Wiki markup''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| cellpadding="0" cellspacing="0" | ||
+ | |align="right"| 432 || .1 | ||
+ | |- | ||
+ | |align="right"| 43 || .21 | ||
+ | |- | ||
+ | |align="right"| 4 || .321 | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| cellpadding="0" cellspacing="0" | ||
+ | |align="right"| 432 || .1 | ||
+ | |- | ||
+ | |align="right"| 43 || .21 | ||
+ | |- | ||
+ | |align="right"| 4 || .321 | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | 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''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {|border="1" cellpadding="4" cellspacing="2" | ||
+ | | | ||
+ | {|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 | ||
+ | |} | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {|border="1" cellpadding="4" cellspacing="2" | ||
+ | | | ||
+ | {|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 | ||
+ | |} | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | 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== | ||
+ | |||
+ | Some users have created [[w:CSS|CSS]] classes and [[Help:templates|templates]] to make table styles easier. Instead of remembering table parameters, you just include an appropriate style class after the <code>{|</code>. 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: | ||
+ | |||
+ | <table border="0" align="center"><tr><td width="46%"> | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| border="1" cellpadding="2" | ||
+ | |+Multiplication table | ||
+ | |- | ||
+ | ! &times; !! 1 !! 2 !! 3 | ||
+ | |- | ||
+ | ! 1 | ||
+ | | 1 || 2 || 3 | ||
+ | |- | ||
+ | ! 2 | ||
+ | | 2 || 4 || 6 | ||
+ | |- | ||
+ | ! 3 | ||
+ | | 3 || 6 || 9 | ||
+ | |- | ||
+ | ! 4 | ||
+ | | 4 || 8 || 12 | ||
+ | |- | ||
+ | ! 5 | ||
+ | | 5 || 10 || 15 | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | </td><td> </td><td width="48%"> | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| 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 | ||
+ | |} | ||
+ | </blockquote></td></tr><tr> | ||
+ | <td colspan="3" align="center">becomes this:</td></tr> | ||
+ | <tr><td width="46%"> | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| class="wikitable" | ||
+ | |+Multiplication table | ||
+ | |- | ||
+ | ! &times; !! 1 !! 2 !! 3 | ||
+ | |- | ||
+ | ! 1 | ||
+ | | 1 || 2 || 3 | ||
+ | |- | ||
+ | ! 2 | ||
+ | | 2 || 4 || 6 | ||
+ | |- | ||
+ | ! 3 | ||
+ | | 3 || 6 || 9 | ||
+ | |- | ||
+ | ! 4 | ||
+ | | 4 || 8 || 12 | ||
+ | |- | ||
+ | ! 5 | ||
+ | | 5 || 10 || 15 | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | </td><td> </td><td width="48%"> | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| 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 | ||
+ | |} | ||
+ | </blockquote></td></tr></table> | ||
+ | |||
+ | simply by replacing inline CSS for the table by <code>class="wikitable"</code>. This is because the ''wikitable'' class in [[MediaWiki:Common.css]] contains a number of ''table.wikitable'' [[w:CSS|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''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><pre><nowiki> | ||
+ | {| class="wikitable" style="font-style:italic; font-size:120%; border:3px dashed red;" | ||
+ | |+Multiplication table | ||
+ | |- | ||
+ | ! &times; !! 1 !! 2 !! 3 | ||
+ | |- | ||
+ | ! 1 | ||
+ | | 1 || 2 || 3 | ||
+ | |- | ||
+ | ! 2 | ||
+ | | 2 || 4 || 6 | ||
+ | |- | ||
+ | ! 3 | ||
+ | | 3 || 6 || 9 | ||
+ | |- | ||
+ | ! 4 | ||
+ | | 4 || 8 || 12 | ||
+ | |- | ||
+ | ! 5 | ||
+ | | 5 || 10 || 15 | ||
+ | |} | ||
+ | </nowiki></pre></blockquote> | ||
+ | |||
+ | '''What it looks like in your browser''' | ||
+ | <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"> | ||
+ | {| 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 | ||
+ | |} | ||
+ | </blockquote> | ||
+ | |||
+ | 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 <code><big></code> instead of "font-size:120%", or Wiki markup like <code><nowiki>''text''</nowiki></code> instead of "font-style:italic". | ||
+ | |||
+ | ==Other table syntax== | ||
+ | Other types of '''table''' syntax that MediaWiki supports: | ||
+ | #XHTML | ||
+ | #HTML and wiki <nowiki><td></nowiki> syntax ('''Do not use''') | ||
+ | |||
+ | All three are supported by MediaWiki and create (currently) valid HTML output, but the pipe syntax is the simplest, especially for people who are already familiar with HTML. Also, HTML and wiki <nowiki><td></nowiki> syntax will not necessarily remain browser-supported in the upcoming future, especially on handheld internet-accessible devices. | ||
+ | |||
+ | See also [[w:Table (HTML)|Table (HTML)]], [[w:HTML element#Tables|HTML element#Tables]]. Note however that the <code>thead</code>, <code>tbody</code>, <code>tfoot</code>, <code>colgroup</code>, and <code>col</code> elements are currently not [[Help:HTML in wikitext#Permitted_HTML|supported in MediaWiki]]. | ||
+ | |||
+ | ===Comparison of table syntax=== | ||
+ | <table class="wikitable"> | ||
+ | <tr><th> <th>XHTML <th>HTML & Wiki-td <th>Wiki-pipe | ||
+ | |||
+ | <tr> | ||
+ | <th>Table | ||
+ | <td><nowiki><table></table></nowiki> | ||
+ | <td><nowiki><table></table></nowiki> | ||
+ | <td><pre><nowiki>{| params | ||
+ | |}</nowiki></pre> | ||
+ | |||
+ | <tr> | ||
+ | <th>Caption | ||
+ | <td><nowiki><caption></caption></nowiki> | ||
+ | <td><nowiki><caption></caption></nowiki> | ||
+ | <td><pre><nowiki>|+ caption</nowiki></pre> | ||
+ | |||
+ | <tr> | ||
+ | <th>Row | ||
+ | <td><nowiki><tr></tr></nowiki> | ||
+ | <td><nowiki><tr></nowiki> | ||
+ | <td><pre><nowiki>|- params </nowiki></pre> | ||
+ | |||
+ | <tr> | ||
+ | <th>Data cell | ||
+ | |||
+ | <td> | ||
+ | <nowiki><td>cell1</td></nowiki><br> | ||
+ | <nowiki><td>cell2</td></nowiki> | ||
+ | |||
+ | <td> | ||
+ | <nowiki><td>cell1</nowiki><br> | ||
+ | <nowiki><td>cell2</nowiki> | ||
+ | |||
+ | <td> | ||
+ | <pre><nowiki>| cell1 | ||
+ | | cell2</nowiki></pre> | ||
+ | |||
+ | <tr> | ||
+ | <th>Data cell | ||
+ | <td><nowiki><td>cell1</td> <td>cell2</td> <td>cell3</td></nowiki> | ||
+ | <td><nowiki><td>cell1 <td>cell2 <td>cell3</nowiki> | ||
+ | <td><pre><nowiki>|cell1||cell2||cell3</nowiki></pre> | ||
+ | |||
+ | <tr> | ||
+ | <th>Header cell | ||
+ | <td><nowiki><th></th></nowiki> | ||
+ | <td><nowiki><th></nowiki> | ||
+ | <td><pre><nowiki>! heading</nowiki></pre> | ||
+ | |||
+ | <tr> | ||
+ | <th rowspan="2">Sample table | ||
+ | <td colspan="3"> | ||
+ | <table align="center" border="1" cellspacing="0" cellpadding="3"> | ||
+ | <tr> | ||
+ | <td>1</td> | ||
+ | <td>2</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>3</td> | ||
+ | <td>4</td> | ||
+ | </tr> | ||
+ | </table> | ||
+ | |||
+ | <tr> | ||
+ | <td><pre><nowiki> | ||
+ | <table> | ||
+ | <tr> | ||
+ | <td>1</td> | ||
+ | <td>2</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>3</td> | ||
+ | <td>4</td> | ||
+ | </tr> | ||
+ | </table> | ||
+ | </nowiki></pre> | ||
+ | |||
+ | <td><pre><nowiki> | ||
+ | <table> | ||
+ | <tr> | ||
+ | <td> 1 <td> 2 | ||
+ | <tr> | ||
+ | <td> 3 <td> 4 | ||
+ | </table> | ||
+ | </nowiki></pre> | ||
+ | |||
+ | <td><pre><nowiki> | ||
+ | {| | ||
+ | | 1 || 2 | ||
+ | |- | ||
+ | | 3 || 4 | ||
+ | |}</nowiki></pre> | ||
+ | |||
+ | <tr> | ||
+ | <th rowspan="2">Sample table | ||
+ | <td colspan="3"> | ||
+ | <table align="center" border="1" cellspacing="0" cellpadding="3"> | ||
+ | <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> | ||
+ | |||
+ | <tr> | ||
+ | <td><pre><nowiki> | ||
+ | <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> | ||
+ | </nowiki></pre> | ||
+ | |||
+ | <td><pre><nowiki> | ||
+ | <table> | ||
+ | <tr> | ||
+ | <td> 1 <td> 2 | ||
+ | <tr> | ||
+ | <td> 3 <td> 4 | ||
+ | <tr> | ||
+ | <td> 5 <td> 6 | ||
+ | </table> | ||
+ | </nowiki></pre> | ||
+ | |||
+ | <td><pre><nowiki> | ||
+ | {| | ||
+ | | 1 || 2 | ||
+ | |- | ||
+ | | 3 || 4 | ||
+ | |- | ||
+ | | 5 || 6 | ||
+ | |}</nowiki></pre> | ||
+ | |||
+ | <tr> | ||
+ | <th>Pros | ||
+ | <td valign="top"> | ||
+ | * Can be previewed/debugged with any XHTML editor | ||
+ | * Can be formatted for easier reading | ||
+ | * Well-known | ||
+ | |||
+ | <td valign="top"> | ||
+ | * Can be previewed/debugged with any HTML editor | ||
+ | * Can be formatted for easier reading | ||
+ | * Well-known | ||
+ | * Takes less space than XHTML | ||
+ | <td valign="top"> | ||
+ | * Easy to write | ||
+ | * Easy to read | ||
+ | * Takes little space | ||
+ | |||
+ | <tr> | ||
+ | <th>Cons | ||
+ | <td valign="top"> | ||
+ | * Tedious | ||
+ | * Takes a lot of space | ||
+ | * Difficult to read quickly | ||
+ | |||
+ | <td valign="top"> | ||
+ | * Should not be used | ||
+ | * Confusing, especially for people with little HTML experience | ||
+ | * Poorly formed | ||
+ | * Poorly delimited | ||
+ | * Generally odd looking | ||
+ | * May not have browser support in future | ||
+ | |||
+ | <td valign="top"> | ||
+ | * Unfamiliar syntax | ||
+ | * Rigid structure | ||
+ | * Cannot be indented | ||
+ | * Text (as in HTML tags) may be easier for some people to read than series of pipes, plus signs, exclamation marks, etc. | ||
+ | * Is nothing more than a shortcut for HTML-style tags. Not easily understood by those unfamiliar with HTML table concepts | ||
+ | |||
+ | <tr><th> <th>XHTML <th>HTML & Wiki-td <th>Wiki-pipe | ||
+ | </table> | ||
+ | |||
+ | ==Pipe syntax in terms of the HTML produced== | ||
+ | The pipe syntax, developed by [[m:User: Magnus Manske| Magnus Manske]], substitutes pipes (<nowiki>|</nowiki>) for HTML. There is an [http://www.uni-bonn.de/~manfear/html2wiki-tables.php 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 <code>||</code> to separate cells on a single line. The parameters are optional. | ||
+ | |||
+ | ===Tables=== | ||
+ | A [[w:Table (HTML)|table]] is defined by | ||
+ | <nowiki> | ||
+ | {| ''params'' | ||
+ | |} | ||
+ | </nowiki> | ||
+ | which equals | ||
+ | <nowiki> | ||
+ | <table ''params''>Insert non-formatted text here | ||
+ | </table> | ||
+ | </nowiki> | ||
+ | |||
+ | :''Careful'': You '''must include''' the '''space''' between <code>'''{|'''</code> and <code>''params''</code>, or the first parameter gets ignored. | ||
+ | |||
+ | ===Rows=== | ||
+ | <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=== | ||
+ | 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=== | ||
+ | Functions the same way as TD, except "!" is used instead of the opening "|". "!!" can be used instead of "||". Parameters still use "|", though! Example: | ||
+ | <nowiki>!</nowiki>''params''|cell1 | ||
+ | |||
+ | ===[[Help:Table Caption|Captions]]=== | ||
+ | |||
+ | 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 == | ||
+ | |||
+ | A simple wiki markup table codes inside a ''Code box'' can be seen below. | ||
+ | |||
+ | <pre> | ||
+ | {| border="5" cellspacing="5" cellpadding="2" | ||
+ | | style="text-align: center;" | [[Image:gnome-system.png]] | ||
+ | |- | ||
+ | ! Computer | ||
+ | |- | ||
+ | | Processor Speed: 1.8 GHz | ||
+ | |} | ||
+ | </pre> | ||
+ | |||
+ | Above codes produces / displays below table: | ||
+ | |||
+ | {| border="5" cellspacing="5" cellpadding="2" style="background-color: transparent;" | ||
+ | | style="text-align: center;" | [[Image:gnome-system.png]] | ||
+ | |- | ||
+ | ! Computer | ||
+ | |- | ||
+ | | Processor Speed: 1.8 GHz | ||
+ | |} | ||
+ | |||
+ | Below codes, 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. | ||
+ | |||
+ | {| border="0" cellpadding="2" cellspacing="0" style="background-color: transparent;" | ||
+ | | width="10%" | | ||
+ | |<pre> | ||
+ | <pre> | ||
+ | {| border="5" cellspacing="5" cellpadding="2" | ||
+ | | style="text-align: center;" | [[Image:gnome-system.png]] | ||
+ | |- | ||
+ | ! Computer | ||
+ | |- | ||
+ | | Processor Speed: 1.8 GHz | ||
+ | |} | ||
+ | </pre> | ||
+ | </pre> | ||
+ | | width="10%" | | ||
+ | |} | ||
+ | |||
+ | Note that, HTML tag '''<tt><pre></tt>''' was used to achieve displaying the above codes and the ''Code box''. | ||
+ | |||
+ | === Other alternatives to display table code === | ||
+ | |||
+ | 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 <tt><pre></tt> tag causes to keep the code line intact, unless a [[w:End-of-line|EOL]] ([[w:Carriage return|CR]]/[[w:Line feed|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 ones. To solve such problem, using the '''<tt><p></tt>''', '''<tt><tt></tt>''' and '''<tt><br /></tt>''' HTML tags, are better than using the '''<tt><pre></tt>''' tag, as those will not result in moving the scroll-bar right (or left) side for viewing, by keeping all the codes to the same width as the web browser window's width. By placing the codes inside the <tt><tt>...</tt></tt> HTML tags, codes are displayed with a [[w:Non-proportional font|fixed width]] text/font, (like the <tt><pre></tt> tag uses) for easier reading. HTML tag <tt><br /></tt> is used to display (or bring) next line of codes, starting from the next line. HTML tag <tt><p></tt> 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 <tt><pre></tt> tag, which gets these properties from the [http://en.wikipedia.org/style/monobook/main.css main.css] stylesheet file). | ||
+ | |||
+ | An example of table code with a long line is: | ||
+ | |||
+ | <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: white;"> 1.8 GHz </span>''' <br /> | ||
+ | |} | ||
+ | </tt> </p> | ||
+ | |||
+ | producing the below table: | ||
+ | |||
+ | {| 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> | ||
+ | |} | ||
+ | |||
+ | ''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> | ||
+ | <p style="padding: 1em; border: 1px dashed #2f6fab; color: Black; background-color: #f9f9f9; line-height: 1.1em;"> <tt> <br /> | ||
+ | <nowiki><nowiki>{|</nowiki></nowiki> border="5" cellspacing="5" cellpadding="2" <br /> <br /> | ||
+ | | style="text-align: center;" | '''<nowiki>'''<nowiki>[[</nowiki>'''</nowiki>'''Image:gnome-system.png]] <br /> <br /> | ||
+ | |- <br /> <br /> | ||
+ | ! Computer <br /> <br /> | ||
+ | |- <br /> <br /> | ||
+ | '''| style="color: yellow; background-color: green;" | Processor Speed: <nowiki><nowiki><span style="color: white;"></nowiki></nowiki> 1.8 GHz <nowiki><nowiki></span></nowiki></nowiki> <br />''' <br /> | ||
+ | <nowiki><nowiki>|}</nowiki></nowiki> <br /> <br /> | ||
+ | </tt> </p> | ||
+ | </tt></p> | ||
+ | |||
+ | See the above codes, note that, <tt><nowiki></tt>...<tt></nowiki></tt> 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 <tt><nowiki></tt>...<tt></nowiki></tt> tags. If these codes were to be displayed inside another table, then, each '''|''' (pipe) & '''!''' (Exclamation mark) symbol also needed to be enclosed inside the <tt><nowiki></tt> 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 '''|''' ([[w:Vertical bar|pipe symbol]]) character with <tt>'''&#124;'''</tt> (HTML decimal entity code), replace each '''!''' ([[w:Exclamation mark|exclamation mark]]) with <tt>'''&#33;'''</tt> code, replace '''{''' (beginning curly/second [[w:Bracket|bracket]]) with <tt>'''&#123;'''</tt> and we may replace '''}''' (closing curly/second bracket) with <tt>'''&#125;'''</tt> code. Also replace the '''<''' (less than sign, or beginning angle bracket) with <tt>'''&#60;'''</tt> numeric entity code or, replace it with <tt>'''&lt;'''</tt> (HTML symbol entity code). For more on HTML decimal or [[w:Hexadecimal|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 <tt>'''&#91;'''</tt> and we may replace ''']''' (closing square/third bracket) with <tt>'''&#93;'''</tt>. 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). | ||
+ | |||
+ | {| border="0" width="100%" | ||
+ | | By using the numeric entity codes, mentioned in 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''. | ||
+ | | | ||
+ | | width="33%" | | ||
+ | <center> | ||
+ | {| 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> | ||
+ | |} | ||
+ | </center> | ||
+ | |} | ||
+ | |||
+ | <p style="padding: 1em; border: 1px dashed #2f6fab; color: Black; background-color: #f9f9f9; line-height: 1.1em;"> <tt> | ||
+ | <p style="padding: 1em; border: 1px dashed #2f6fab; color: Black; background-color: #f9f9f9; line-height: 1.1em;"> <tt> <br /> | ||
+ | &#123;&#124; border="5" cellspacing="5" cellpadding="2" <br /> <br /> | ||
+ | &#124; style="text-align: center;" &#124; &#91;&#91;Image:gnome-system.png]] <br /> <br /> | ||
+ | &#124;- <br /> <br /> | ||
+ | &#33; Computer <br /> <br /> | ||
+ | &#124;- <br /> <br /> | ||
+ | '''&#124; style="color: yellow; background-color: green;" &#124; Processor Speed: &#60;span style="color: red;"> 1.8 GHz &#60;/span> <br />''' <br /> | ||
+ | &#124;&#125; <br /> <br /> | ||
+ | </tt> </p> | ||
+ | </tt> </p> | ||
+ | |||
+ | See also [[Help:Advanced_editing#Disabling_wikitext_interpretation_and.2For_reformatting|disabling wikitext interpretation and/or reformatting]]. | ||
+ | |||
+ | ==See also== | ||
+ | *[[m:simplified table syntax]] | ||
+ | *[[m:wiki markup tables]] | ||
+ | *[[w:en:User:Dcljr/Tables]] | ||
+ | *[[w:Table (HTML)]] | ||
+ | *examples: | ||
+ | **[[w:en:Template talk:Chess position|Chess board]] | ||
+ | **[[w:en:Template talk:Game of Go Position|Go board]] | ||
+ | **[[w:en:Monopoly (game)#Board|Monopoly board]] | ||
+ | **[[m:Template talk:Square 8x8 pentomino example|Square 8x8 pentomino example]] | ||
+ | |||
+ | ==External links== | ||
+ | *[[:de:Wikipedia:Helferlein/EXCEL Tabellenumwandlung|VBA-Macro for EXCEL tableconversion]] published in German-Wikipediaproject (english instructions included) | ||
+ | *[http://www.cnic.org/html2mediawiki.html HTML tables to wiki converter at cnic.org] | ||
+ | *[http://area23.brightbyte.de/csv2wp.php csv2wp] - converts [[w:comma-separated values|comma-separated values]] (CSV) format to pipe syntax. You may use this to import tables from Excel etc. ([[wikipedia:de:Benutzer:Duesentrieb/csv2wp|more information]]) | ||
+ | *[http://www.uni-bonn.de/~manfear/html2wiki-tables.php HTML tables to wiki converter at uni-bonn.de] | ||
+ | *[http://diberri.dyndns.org/html2wiki.html HTML tables to wiki converter at diberri.dyndns.org] | ||
+ | *[http://pywikipediabot.sourceforge.net/ pywikipediabot] (can convert HTML tables to wiki) | ||
+ | |||
+ | {{h:f|enname=Table}} |
This page gives you information about syntax to build wiki-tables.
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:
{|
to begin a table, and |}
to end it. Each one needs to be on its own line: {| table code goes here |}
|+
" and the caption after it:{|
|+ caption
table code goes here
|}
|-
". 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 |}
{| |+ The table's caption |- | cell codes go here |- | cells in the next row go here | more cells in the same row here |}
{| |+ The table's caption |- |Cell 1 || Cell 2 || Cell 3 |- |Cell A |Cell B |Cell C |}
{|
|+ 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 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 |}
{| 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, like m:Template talk:Square 8x8 pentomino example. 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 (unless there are cells which span several columns or rows, see colspan and rowspan in Mélange example below). For empty cells, use the non-breaking space
as content to ensure that the cells are displayed.
To add a visible | into a table use <nowiki>|</nowiki> or |
Both of these generate the same output. Choose a style based on the amount of cells in each row and the total text inside each cell.
Wiki markup
{| | Cell 1, row 1 | Cell 2, row 1 |- | Cell 1, row 2 | Cell 2, row 2 |}
{| | Cell 1, row 1 || Cell 2, row 1 |- | Cell 1, row 2 || Cell 2, row 2 |}
What it looks like in your browser
Cell 1, row 1 Cell 2, row 1 Cell 1, row 2 Cell 2, row 2
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
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
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" | <font color="white"> ghi </font> | jkl |}
What it looks like in your browser
abc def ghi jkl
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"
. (Warning: style="background:inherit"
, does not work with some browsers, including IE6!)
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 it's important equivalent older constructs like width="75%"
should work on more browsers.
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 |- |Pokeball || Regular Pokeball || All Versions |- |Great Ball || Better than a Pokeball || All Versions |}
Name Effect Games Found In Pokeball Regular Pokeball All Versions Great Ball Better than a Pokeball All Versions
One can position the table itself, and all contents in a row, and contents in a cell, but not with a single parameter 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.
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.
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 grey;" valign="top" | right side |- | style="border-bottom:3px solid grey;" | lower left | style="border-bottom:3px solid grey;" | 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 Tiedosto:Wiki.png Tiedosto:Wiki.png Two Wikimedia logos
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
Malline:-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...
This shows one table (in blue) nested inside another table's cell2. Nested tables have to start on a new line.
Wiki markup
{| border="1"
| α
| align="center" | cell2
{| border="2" style="background-color:#ABCDEF;"
| NESTED
|-
| TABLE
|}
| valign="bottom" | the original table again
|}
What it looks like in your browser
α cell2
NESTED TABLE the original table again
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.
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.
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
{| |- | bgcolor="red"|cell1 || width="300" bgcolor="blue"|cell2 || bgcolor="green"|cell3 |}
What it looks like in your browser
cell1 cell2 cell3
A 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" | {|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
Some users have created CSS classes and templates to make table styles easier. 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".
Other types of table syntax that MediaWiki supports:
All three are supported by MediaWiki and create (currently) valid HTML output, but the pipe syntax is the simplest, especially for people who are already familiar with HTML. Also, HTML and wiki <td> syntax 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.
XHTML | HTML & Wiki-td | Wiki-pipe | |||||||
---|---|---|---|---|---|---|---|---|---|
Table | <table></table> | <table></table> | {| params |} | ||||||
Caption | <caption></caption> | <caption></caption> | |+ caption | ||||||
Row | <tr></tr> | <tr> | |- params | ||||||
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></th> | <th> | ! 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 |
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.
A table is defined by {| ''params'' |} which equals <table ''params''>Insert non-formatted text here </table>
{|
and params
, or the first parameter gets ignored.<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:
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>
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
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>
A simple wiki markup table codes 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 codes produces / displays below table:
Tiedosto:Gnome-system.png |
Computer |
---|
Processor Speed: 1.8 GHz |
Below codes, 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.
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 to keep the code line intact, unless a 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 ones. To solve such problem, using the <p>, <tt> and <br /> HTML tags, are better than using the <pre> tag, as those will not result in moving the scroll-bar right (or left) side for viewing, by keeping all the codes to the same width as the web browser window's width. 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:
Tiedosto: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 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.
FAIR is a non-profit organization dedicated to providing well-documented answers to criticisms of the doctrine, practice, and history of The Church of Jesus Christ of Latter-day Saints.
We are a volunteer organization. We invite you to give back.
Donate Now