Help:Tables

From FamilySearch Wiki

(Difference between revisions)
(remove {{dead link}} - link checked OK)
(18 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{how-to-articles}} This topic of this article is how to create tables with Wikitext or HTML. For information on how to copy spreadsheets from Excel and other programs onto a wiki page, see [[Copy Spreadsheets into the Wiki|Copy Spreadsheets into the Wiki]].  
+
{{Help article}}
 +
 
 +
The topic of this article is how to create tables with Wikitext or HTML. For information on how to copy spreadsheets from Excel and other programs onto a wiki page, see [[Copy Spreadsheets into the Wiki|Copy Spreadsheets into the Wiki]].  
 +
 
  
 
<u>'''Quick Reference:'''</u>  
 
<u>'''Quick Reference:'''</u>  
  
{| width="200" cellspacing="0" cellpadding="5" border="1"
+
{| border="1" cellspacing="0" cellpadding="5" width="200"
 
|-
 
|-
 
| <nowiki>{|</nowiki>  
 
| <nowiki>{|</nowiki>  
Line 18: Line 21:
 
|}
 
|}
  
<br>NOTE: It is possible to create tables with Wikitext or HTML by turning off the FCK editor, or Wiki editing tool. '''Detailed instructions for beginning users are not included in this article. '''Special instructions are available for [[Copy Spreadsheets into the Wiki|copying spreadsheets or Excel documents into the Wiki]]. Beginners should first read [[Help:Adding basic tables to an article|basic table instructions for beginners]]. Advanced instructions for users who do not want to create tables using Wikitext or HTML are available online at [http://docs.fckeditor.net/FCKeditor_2.x/Users_Guide/Common_Tasks/Tables the FCK editor website]. Learn more about the [[Help:FCK Editor|FCK editor/editing tool]], and [[Help:FCK Editor#Turning_the_editor_tool_off_and_on|how to turn&nbsp;it off and on]].  
+
<br>NOTE: This page explains how to create tables with Wikitext or HTML by turning off the FCK editor, or Wiki editing tool. Instructions for creating basic tables for beginners are available in the article [[Help:Adding basic tables to an article|basic table instructions for beginners]]. ''Advanced instructions for beginning users are not included in this article.''  Advanced instructions for users who do not want to create tables using Wikitext or HTML are available online at [http://docs.fckeditor.net/FCKeditor_2.x/Users_Guide/Common_Tasks/Tables the FCK editor website]. Learn more about the [[Help:FCK Editor|FCK editor/editing tool]], and [[Help:FCK Editor#Turning_the_editor_tool_off_and_on|how to turn&nbsp;it off and on]].  Special instructions are available for [[Copy Spreadsheets into the Wiki|copying spreadsheets or Excel documents into the Wiki]].
  
 
== What you should know before creating a table  ==
 
== What you should know before creating a table  ==
Line 24: Line 27:
 
1. Tables that were created in other programs can be imported into the Wiki, however, the process for doing so is time intensive. It may take less time to re-create a table than import an existing table into the Wiki.  
 
1. Tables that were created in other programs can be imported into the Wiki, however, the process for doing so is time intensive. It may take less time to re-create a table than import an existing table into the Wiki.  
  
3. Tables may be authored in wiki pages using either HTML table elements directly, or using wikicode formatting to define the table. HTML table elements and their use are well described on various web pages and will not be discussed here. The benefit of wikicode is that the table is constructed of character symbols which tend to make it easier to perceive the table structure in the article editing view compared to HTML table elements.  
+
2. Tables may be authored in wiki pages using either HTML table elements directly, or using wikicode formatting to define the table. HTML table elements and their use are well described on various web pages and will not be discussed here. The benefit of wikicode is that the table is constructed of character symbols which tend to make it easier to perceive the table structure in the article editing view compared to HTML table elements.  
  
 
A good general rule of thumb is to use a tables only when necessary. Table markup may complicate page editing.  
 
A good general rule of thumb is to use a tables only when necessary. Table markup may complicate page editing.  
Line 30: Line 33:
 
== Wiki table markup summary  ==
 
== Wiki table markup summary  ==
  
{| width="600" cellspacing="0" cellpadding="5" border="1"
+
{| border="1" cellspacing="0" cellpadding="5" width="600"
 
|-
 
|-
 
| <nowiki>{|</nowiki>  
 
| <nowiki>{|</nowiki>  
Line 54: Line 57:
 
*XHTML attributes. Each mark, except table end, optionally accepts one or more XHTML attributes. Attributes must be on the same line as the mark. Separate attributes from each other with a single space.  
 
*XHTML attributes. Each mark, except table end, optionally accepts one or more XHTML attributes. Attributes must be on the same line as the mark. Separate attributes from each other with a single space.  
 
**Cells and caption (<nowiki>| or ||, ! or !!, and |+</nowiki>) hold content. So separate any attributes from content with a single pipe (|). Cell content may follow on same line or on following lines.  
 
**Cells and caption (<nowiki>| or ||, ! or !!, and |+</nowiki>) hold content. So separate any attributes from content with a single pipe (|). Cell content may follow on same line or on following lines.  
**Table and row marks (<nowiki>{| and |-</nowiki>) do not directly hold content. Do ''not'' add pipe (|) after their optional attributes. If you erroneously add a pipe after attributes for the table mark or row mark the parser will delete it ''and'' your final attribute if it was touching the erroneous pipe!  
+
**Table and row marks (<nowiki>{| and |-</nowiki>) do not directly hold content. Do ''not'' add pipe (|) after their optional attributes. If you erroneously add a pipe after attributes for the table mark or row mark the parser will delete it ''and'' your final attribute if it was touching the erroneous pipe!
 
*Content may (a) follow its cell mark on the same line after any optional XHTML attributes or (b) on lines below the cell mark. Content that uses wiki markup that itself needs to start on a new line, such as lists, headers, or nested tables, must of course be on its own new line.
 
*Content may (a) follow its cell mark on the same line after any optional XHTML attributes or (b) on lines below the cell mark. Content that uses wiki markup that itself needs to start on a new line, such as lists, headers, or nested tables, must of course be on its own new line.
  
Line 63: Line 66:
 
The following table lacks borders and good spacing but shows the simplest wiki markup table structure  
 
The following table lacks borders and good spacing but shows the simplest wiki markup table structure  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
Line 99: Line 102:
 
HTML attributes can be added to tables on this page but have been left out of the following example for simplicity.  
 
HTML attributes can be added to tables on this page but have been left out of the following example for simplicity.  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
Line 127: Line 130:
 
|}
 
|}
  
==== '''Tables with HTML attributes'''  ====
+
== '''Tables with HTML attributes'''  ==
  
 
You can add HTML attributes to make your table look better  
 
You can add HTML attributes to make your table look better  
Line 133: Line 136:
 
'''border="1"'''  
 
'''border="1"'''  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
Line 163: Line 166:
 
'''align="center" border="1"'''  
 
'''align="center" border="1"'''  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
Line 191: Line 194:
 
|}
 
|}
  
==== '''Attributes on cells'''  ====
+
=== '''Attributes on cells'''  ===
  
 
You can put attributes on individual cells. Numbers for example may look better aligned right  
 
You can put attributes on individual cells. Numbers for example may look better aligned right  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
Line 229: Line 232:
 
|}
 
|}
  
==== '''Attributes on rows'''  ====
+
=== '''Attributes on rows'''  ===
  
 
You can put attributes on individual rows, too.  
 
You can put attributes on individual rows, too.  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
Line 245: Line 248:
 
| Pie  
 
| Pie  
 
| align="right" | 500.00
 
| align="right" | 500.00
|- style="color: green; font-style: italic;"
+
|- style="font-style: italic; color: green"
 
| Butter  
 
| Butter  
 
| Ice cream  
 
| Ice cream  
Line 269: Line 272:
 
'''cellspacing="0" border="1"'''  
 
'''cellspacing="0" border="1"'''  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
{| cellspacing="0" border="1"
+
{| border="1" cellspacing="0"
 
|-
 
|-
 
| Orange  
 
| Orange  
Line 299: Line 302:
 
'''cellpadding="20" cellspacing="0" border="1"'''  
 
'''cellpadding="20" cellspacing="0" border="1"'''  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
{| cellspacing="0" cellpadding="20" border="1"
+
{| border="1" cellspacing="0" cellpadding="20"
 
|-
 
|-
 
| Orange  
 
| Orange  
Line 327: Line 330:
 
|}
 
|}
  
''Note: This cellpadding example is not currently working properly on mediawiki.org It is supposed to look like [http://test.wikipedia.org/wiki/Table_test this]''
+
=== 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.
 +
 
 +
The wiki markup code:
 +
<pre style="display: inline-block;">
 +
{| style="width: 75%; height: 200px" border="1"
 +
|-
 +
| abc || def || ghi
 +
|- style="height: 100px;"
 +
| jkl || style="width: 200px;" | mno || pqr
 +
|-
 +
| stu || vwx || yz
 +
|}
 +
</pre>
 +
 
 +
As it appears in a browser:
 +
<div 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
 +
|}
 +
</div>
 +
 
 +
Note that <code>style="</code>inline CSS<code>"</code> has no effect with some browsers. If compatibility is important, equivalent older constructs like <code>width="75%"</code> should work on more browsers.
 +
 
 +
==== Setting column widths ====
 +
To force column widths to specific requirements, rather than accepting the width of the widest text element in a column's cells, follow this example. Note that wrap-around of text is forced.
 +
 
 +
The wiki markup code:
 +
<pre style="display: inline-block;">
 +
{| border="1" cellpadding="2"
 +
! scope="col" width="50" | Name
 +
! scope="col" width="225" | Effect
 +
! scope="col" width="225" | Games Found In
 +
|-
 +
| Poké Ball || Regular Poké Ball || All Versions
 +
|-
 +
| Great Ball || Better than a Poké Ball || All Versions
 +
|}
 +
</pre>
 +
 
 +
<div style="background: white; border: 1px solid black; padding: 1em;">
 +
{| border="1" cellpadding="2"
 +
|-
 +
! scope="col" width="50" | Name
 +
! scope="col" style="width: 225px;" | Effect
 +
! scope="col" style="width: 225px;" | Games Found In
 +
|-
 +
|Poké Ball || Regular Poké Ball || All Versions
 +
|-
 +
|Great Ball || Better than a Poké Ball || All Versions
 +
|}
 +
</div>
 +
 
 +
To set column widths in a table without headers, specify the width in the first cell for each column, like this:
 +
 
 +
<pre style="display: inline-block;">
 +
{| 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 || blih || bluh
 +
|}
 +
</pre>
 +
 
 +
<div style="background: white; border: 1px solid black; padding: 1em;">
 +
{| border="1" cellpadding="2"
 +
|-
 +
| style="width: 100pt;" | This column is 100 points wide
 +
| style="width: 200pt;" | This column is 200 points wide
 +
| style="width: 300pt;" | This column is 300 points wide
 +
|-
 +
| blah || blih || bluh
 +
|}
 +
</div>
 +
 
 +
One application of setting the widths is aligning columns of consecutive tables:
 +
 
 +
{| border="1" cellpadding="2"
 +
|-
 +
! scope="col" style="width: 350px;" | Country
 +
! scope="col" style="width: 225px;" | Capital
 +
|-
 +
| The Netherlands || Amsterdam
 +
|}
 +
 
 +
{| border="1" cellpadding="2"
 +
|-
 +
! scope="col" style="width: 350px;" | Country
 +
! scope="col" style="width: 225px;" | Capital
 +
|-
 +
| France || Paris
 +
|}
 +
 
 +
=====Nowrap=====
 +
In a table that spans the entire width of a page, cells narrower than the widest cell tend to wrap. To keep an entire column from wrapping, use <tt>style=white-space:nowrap</tt> in a non-header cell on the longest/widest cell to affect the entire column.
 +
 
 +
Before:
 +
{|"class=wikitable sortable" border="1"
 +
|-
 +
! scope="col" | Episode
 +
! scope="col" | Date
 +
! scope="col" | Summary
 +
|-
 +
|"The Journey Begins"
 +
|January 1, 2010
 +
|[[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.
 +
|-
 +
|"When Episodes Attack"
 +
|January 8, 2010
 +
|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.
 +
|-
 +
|"So Long"
 +
|January 15, 2010
 +
|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.
 +
|}
 +
 
 +
After:
 +
{|"class=wikitable sortable" border="1"
 +
|-
 +
! scope="col" | Episode
 +
! scope="col" | Date
 +
! scope="col" | Summary
 +
|-
 +
|"The Journey Begins"
 +
|January 1, 2010
 +
|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.
 +
|-
 +
|style=white-space:nowrap|"When Episodes Attack"
 +
|January 8, 2010
 +
|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.
 +
|-
 +
|"So Long"
 +
|style=white-space:nowrap|January 15, 2010
 +
|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.
 +
|}
  
<br>
 
  
==== Tables with HTML attributes and CSS styles  ====
+
=== Tables with HTML attributes and CSS styles  ===
  
 
CSS style attributes can be added with or without other HTML attributes  
 
CSS style attributes can be added with or without other HTML attributes  
Line 337: Line 480:
 
'''style="color:green;background-color:#ffffcc;" cellpadding="20" cellspacing="0" border="1"'''  
 
'''style="color:green;background-color:#ffffcc;" cellpadding="20" cellspacing="0" border="1"'''  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
{| cellspacing="0" cellpadding="20" border="1" style="color: green; background-color: rgb(255, 255, 204);"
+
{| style="background-color: rgb(255,255,204); color: green" border="1" cellspacing="0" cellpadding="20"
 
|-
 
|-
 
| Orange  
 
| Orange  
Line 365: Line 508:
 
|}
 
|}
  
==== Scrolling tables<br> ====
+
=== Scrolling tables  ===
  
 
Some tables contain enough data that they don't fit in the allotted space left to right. To create a table that scrolls left to right, put the table within div codes.  
 
Some tables contain enough data that they don't fit in the allotted space left to right. To create a table that scrolls left to right, put the table within div codes.  
<div style="border: 2px solid rgb(221, 221, 221); overflow-y: hidden; overflow-x: auto; padding: 0.2em; width: 99%;" id="imageContainer">
+
<div style="border-bottom: rgb(221,221,221) 2px solid; border-left: rgb(221,221,221) 2px solid; padding-bottom: 0.2em; overflow-x: auto; overflow-y: hidden; padding-left: 0.2em; width: 99%; padding-right: 0.2em; border-top: rgb(221,221,221) 2px solid; border-right: rgb(221,221,221) 2px solid; padding-top: 0.2em" id="imageContainer">
{| width="1000" cellspacing="1" cellpadding="10" border="1"
+
{| border="1" cellspacing="1" cellpadding="10" width="1000"
 
|-
 
|-
| Heading 1<br>  
+
| Heading 1<br>
| Heading 2<br>  
+
| Heading 2<br>
| Heading 3<br>  
+
| Heading 3<br>
| Heading 4<br>  
+
| Heading 4<br>
| Heading 5<br>  
+
| Heading 5<br>
| Heading 6<br>  
+
| Heading 6<br>
| Heading 7<br>  
+
| Heading 7<br>
| Heading 8<br>  
+
| Heading 8<br>
| Heading 9<br>  
+
| Heading 9<br>
 
| Heading 10<br>
 
| Heading 10<br>
 
|-
 
|-
| data 1<br>  
+
| data 1<br>
| data 2<br>  
+
| data 2<br>
| data 3<br>  
+
| data 3<br>
| data 4<br>  
+
| data 4<br>
| data 5<br>  
+
| data 5<br>
| data 6<br>  
+
| data 6<br>
| data 7<br>  
+
| data 7<br>
| data 8<br>  
+
| data 8<br>
| data 9<br>  
+
| data 9<br>
 
| data 10<br>
 
| data 10<br>
 
|}
 
|}
</div> <br>
+
</div>
 +
<br>
 
<pre>&lt;div style="border: 2px solid rgb(221, 221, 221); overflow-y: hidden; overflow-x: auto;  
 
<pre>&lt;div style="border: 2px solid rgb(221, 221, 221); overflow-y: hidden; overflow-x: auto;  
 
padding: 0.2em; width: 99%;" id="imageContainer"&gt;
 
padding: 0.2em; width: 99%;" id="imageContainer"&gt;
Line 421: Line 565:
 
|}
 
|}
 
&lt;/div&gt;
 
&lt;/div&gt;
</pre>  
+
</pre>
<br>  
+
<br>
 +
 
 +
== Table with TH headings  ==
 +
 
 +
TH (HTML table headings) can be created by using&nbsp;! instead of |. Headings usually show up bold and centered by default.
 +
 
 +
==== Top headings  ====
 +
 
 +
'''Each column'''
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
{| cellspacing="0" cellpadding="20" border="1"
+
{| border="1" cellspacing="0" cellpadding="20"
 
|-
 
|-
 
! Yummy  
 
! Yummy  
Line 460: Line 612:
 
'''Colspan="2"'''  
 
'''Colspan="2"'''  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
{| cellspacing="0" cellpadding="20" border="1"
+
{| border="1" cellspacing="0" cellpadding="20"
 
|-
 
|-
 
! colspan="2" | Yummies
 
! colspan="2" | Yummies
Line 496: Line 648:
 
'''Default'''  
 
'''Default'''  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
{| cellspacing="0" cellpadding="20" border="1"
+
{| border="1" cellspacing="0" cellpadding="20"
 
|-
 
|-
 
! Fruit  
 
! Fruit  
Line 534: Line 686:
 
Right justified side headings can be done as follows  
 
Right justified side headings can be done as follows  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
{| cellspacing="0" cellpadding="20" border="1"
+
{| border="1" cellspacing="0" cellpadding="20"
 
|-
 
|-
 
! align="right" | Fruit  
 
! align="right" | Fruit  
Line 572: Line 724:
 
A table caption can be added to the top of any table as follows  
 
A table caption can be added to the top of any table as follows  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
{| cellspacing="0" cellpadding="20" border="1"
+
{| border="1" cellspacing="0" cellpadding="20"
 
|+ Food complements  
 
|+ Food complements  
 
|-
 
|-
Line 605: Line 757:
 
Attributes can be added to the caption as follows  
 
Attributes can be added to the caption as follows  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
{| cellspacing="0" cellpadding="20" border="1"
+
{| border="1" cellspacing="0" cellpadding="20"
 
|+ ''Food complements''  
 
|+ ''Food complements''  
 
|-
 
|-
Line 647: Line 799:
  
 
'''Wiki markup'''  
 
'''Wiki markup'''  
<blockquote style="border: 1px solid rgb(153, 153, 153); padding: 1em; background: none repeat scroll 0% 0% white;"><pre>{| class="sortable" border="1"
+
<blockquote style="border-bottom: rgb(153,153,153) 1px solid; border-left: rgb(153,153,153) 1px solid; padding-bottom: 1em; padding-left: 1em; padding-right: 1em; background: white; border-top: rgb(153,153,153) 1px solid; border-right: rgb(153,153,153) 1px solid; padding-top: 1em"><pre>{| class="sortable" border="1"
 
|+ '''Sortable table'''
 
|+ '''Sortable table'''
 
|-
 
|-
Line 662: Line 814:
 
| e || 0 || 1601-08-13 || sorted.
 
| e || 0 || 1601-08-13 || sorted.
 
|}
 
|}
</pre></blockquote>  
+
</pre></blockquote>
 
'''What it looks like in your browser'''  
 
'''What it looks like in your browser'''  
<blockquote style="border: 1px solid rgb(153, 153, 153); padding: 1em; background: none repeat scroll 0% 0% white;">
+
<blockquote style="border-bottom: rgb(153,153,153) 1px solid; border-left: rgb(153,153,153) 1px solid; padding-bottom: 1em; padding-left: 1em; padding-right: 1em; background: white; border-top: rgb(153,153,153) 1px solid; border-right: rgb(153,153,153) 1px solid; padding-top: 1em">
{| border="1" class="sortable"
+
{| class="sortable" border="1"
 
|+ '''Sortable table'''  
 
|+ '''Sortable table'''  
 
|-
 
|-
Line 698: Line 850:
 
| sorted.
 
| sorted.
 
|}
 
|}
</blockquote>  
+
</blockquote>
 
== Table with H1, H2, H3 etc. headings  ==
 
== Table with H1, H2, H3 etc. headings  ==
  
Line 707: Line 859:
 
Keep the heading hierarchy consistent with the rest of the page so that the table of contents at page top works correctly.  
 
Keep the heading hierarchy consistent with the rest of the page so that the table of contents at page top works correctly.  
  
{| width="100%" class="FCK__ShowTableBorders"
+
{| class="FCK__ShowTableBorders" width="100%"
 
|-
 
|-
 
| width="50%" |  
 
| width="50%" |  
{| cellspacing="0" cellpadding="20" border="1"
+
{| border="1" cellspacing="0" cellpadding="20"
 
|-
 
|-
 
| colspan="2" |  
 
| colspan="2" |  
=== Yummiest ===
+
=== Yummiest ===
  
 
|-
 
|-
Line 742: Line 894:
 
|}
 
|}
  
== Tips  ==
 
  
To merge or select cells press the 'CTRL' key while clicking in the cells.<br>  
+
 
 +
 
 +
== Tips  ==
 +
{{Contributor Help badge}}
 +
To merge or select cells press the 'CTRL' key while clicking in the cells.<br>
  
 
A good way of formatting a table would be something of the form:  
 
A good way of formatting a table would be something of the form:  
  
<nowiki>{| width="x%" border="1" cellspacing="0" style="margin: 1em auto;"</nowiki><br>  
+
<nowiki>{| width="x%" border="1" cellspacing="0" style="margin: 1em auto;"</nowiki><br>
  
 
but you could also add:  
 
but you could also add:  
Line 758: Line 913:
 
Remember that you don't always have to set the width to 100%. This can be an irritation when the table just contains small amounts of data but is forced to stretch to fit the full screen:  
 
Remember that you don't always have to set the width to 100%. This can be an irritation when the table just contains small amounts of data but is forced to stretch to fit the full screen:  
  
{| width="25%" cellspacing="0" border="1" style="margin: 1em auto;"
+
{| style="margin: 1em auto" border="1" cellspacing="0" width="25%"
 
|-
 
|-
 
! left header  
 
! left header  
Line 772: Line 927:
 
but  
 
but  
  
{| width="100%" cellspacing="0" border="1"
+
{| border="1" cellspacing="0" width="100%"
 
|-
 
|-
 
! left header  
 
! left header  
Line 785: Line 940:
 
The best solution is 'trial-and-error'. Keep using the ''Show preview'' button and see what it looks like?  
 
The best solution is 'trial-and-error'. Keep using the ''Show preview'' button and see what it looks like?  
  
== Caveat  ==
+
=== Caveat  ===
  
 
'''Negative numbers'''  
 
'''Negative numbers'''  
Line 791: Line 946:
 
Negative value minus sign can break your table (it may display missing some values) if you start a cell on a new line with a negative number or a parameter that evaluates to a negative number (|-6) because that is the wiki markup for table row, not table cell. To avoid this, insert a space before the value (| -6) or use in-line cell markup (||-6).  
 
Negative value minus sign can break your table (it may display missing some values) if you start a cell on a new line with a negative number or a parameter that evaluates to a negative number (|-6) because that is the wiki markup for table row, not table cell. To avoid this, insert a space before the value (| -6) or use in-line cell markup (||-6).  
  
=== See Also  ===
+
== See Also  ==
 
+
{{Contributor Help badge}}
=== See Also  ===
+
 
+
 
*[[Help:Adding basic tables to an article]]  
 
*[[Help:Adding basic tables to an article]]  
 
*[[Copy Spreadsheets into the Wiki]]  
 
*[[Copy Spreadsheets into the Wiki]]  
 
*WikiMedia's article on [http://meta.wikimedia.org/wiki/Help:Sorting Sortable tables]  
 
*WikiMedia's article on [http://meta.wikimedia.org/wiki/Help:Sorting Sortable tables]  
 
*WikiMedia's article on [http://meta.wikimedia.org/wiki/Help:Collapsing Collapsible tables]
 
*WikiMedia's article on [http://meta.wikimedia.org/wiki/Help:Collapsing Collapsible tables]
 +
 +
{{Contributor help-navbox}} {{Editing help}}
  
 
[[Category:Help|{{PAGENAME}}]]
 
[[Category:Help|{{PAGENAME}}]]

Revision as of 21:32, 8 November 2012

Help-content.png This help article will guide you as you edit in the Wiki. See Contributor Help for more help articles.


The topic of this article is how to create tables with Wikitext or HTML. For information on how to copy spreadsheets from Excel and other programs onto a wiki page, see Copy Spreadsheets into the Wiki.


Quick Reference:

{| start table
|- table row
| table data cell or column
|} end table


NOTE: This page explains how to create tables with Wikitext or HTML by turning off the FCK editor, or Wiki editing tool. Instructions for creating basic tables for beginners are available in the article basic table instructions for beginners. Advanced instructions for beginning users are not included in this article. Advanced instructions for users who do not want to create tables using Wikitext or HTML are available online at the FCK editor website. Learn more about the FCK editor/editing tool, and how to turn it off and on. Special instructions are available for copying spreadsheets or Excel documents into the Wiki.

Contents

What you should know before creating a table

1. Tables that were created in other programs can be imported into the Wiki, however, the process for doing so is time intensive. It may take less time to re-create a table than import an existing table into the Wiki.

2. Tables may be authored in wiki pages using either HTML table elements directly, or using wikicode formatting to define the table. HTML table elements and their use are well described on various web pages and will not be discussed here. The benefit of wikicode is that the table is constructed of character symbols which tend to make it easier to perceive the table structure in the article editing view compared to HTML table elements.

A good general rule of thumb is to use a tables only when necessary. Table markup may complicate page editing.

Wiki table markup summary

{| start table
|+ table caption, optional; only one per table and between table start and first row
|- table row, optional on first row -- wiki engine assumes the first row
! table header cell, optional. Consecutive table headers may be added on same line separated by double marks (!!) or start on new lines, each with its own single mark (!).
| table data cell, required! Consecutive table data cells may be added on same line separated by double marks (||) or start on new lines, each with its own single mark (|).
|} end table
  • The above marks must start on a new line except the double || and !! for optionally adding consecutive cells to a line.
  • XHTML attributes. Each mark, except table end, optionally accepts one or more XHTML attributes. Attributes must be on the same line as the mark. Separate attributes from each other with a single space.
    • Cells and caption (| or ||, ! or !!, and |+) hold content. So separate any attributes from content with a single pipe (|). Cell content may follow on same line or on following lines.
    • Table and row marks ({| and |-) do not directly hold content. Do not add pipe (|) after their optional attributes. If you erroneously add a pipe after attributes for the table mark or row mark the parser will delete it and your final attribute if it was touching the erroneous pipe!
  • Content may (a) follow its cell mark on the same line after any optional XHTML attributes or (b) on lines below the cell mark. Content that uses wiki markup that itself needs to start on a new line, such as lists, headers, or nested tables, must of course be on its own new line.

Simple table

Plain Tables

The following table lacks borders and good spacing but shows the simplest wiki markup table structure

Orange Apple
Bread Pie
Butter Ice cream
{|
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

Alternative Tables

For more table-ish looking wiki markup cells can be listed on one line separated by ||. This does not scale well for longer cell content such as paragraphs. It works well for short bits of content however, such as our example table.

Extra spaces within cells in the wiki markup can be added, as I have done in the wiki markup below, to make the wiki markup itself look better but they do not affect the actual table rendering.

HTML attributes can be added to tables on this page but have been left out of the following example for simplicity.

Orange Apple more
Bread Pie more
Butter Ice cream and more
{|
|  Orange    ||   Apple   ||   more
|-
|   Bread    ||   Pie     ||   more
|-
|   Butter   || Ice cream ||  and more
|}

Tables with HTML attributes

You can add HTML attributes to make your table look better

border="1"

Orange Apple
Bread Pie
Butter Ice cream
{| border="1"
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

align="center" border="1"

Orange Apple
Bread Pie
Butter Ice cream
{| align="center" border="1"
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

Attributes on cells

You can put attributes on individual cells. Numbers for example may look better aligned right

Orange Apple 12,333.00
Bread Pie 500.00
Butter Ice cream 1.00
{| border="1"
|Orange
|Apple
|align="right"|12,333.00
|-
|Bread
|Pie
|align="right"|500.00
|-
|Butter
|Ice cream
|align="right"|1.00
|}

Attributes on rows

You can put attributes on individual rows, too.

Orange Apple 12,333.00
Bread Pie 500.00
Butter Ice cream 1.00
{| border="1"
|Orange
|Apple
|align="right"|12,333.00
|-
|Bread
|Pie
|align="right"|500.00
|- style="font-style:italic;color:green;"
|Butter
|Ice cream
|align="right"|1.00
|}

cellspacing="0" border="1"

Orange Apple
Bread Pie
Butter Ice cream
{| cellspacing="0" border="1"
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

cellpadding="20" cellspacing="0" border="1"

Orange Apple
Bread Pie
Butter Ice cream
{| cellpadding="20" cellspacing="0" border="1"
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

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.

The wiki markup code:

{| style="width: 75%; height: 200px" border="1"
|-
| abc || def || ghi
|- style="height: 100px;"
| jkl || style="width: 200px;" | mno || pqr
|-
| stu || vwx || yz
|}

As it appears in a 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 column widths

To force column widths to specific requirements, rather than accepting the width of the widest text element in a column's cells, follow this example. Note that wrap-around of text is forced.

The wiki markup code:

{| border="1" cellpadding="2"
! scope="col" width="50" | Name
! scope="col" width="225" | Effect
! scope="col" 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 || blih || bluh
|}
This column is 100 points wide This column is 200 points wide This column is 300 points wide
blah blih bluh

One application of setting the widths is aligning columns of consecutive tables:

Country Capital
The Netherlands Amsterdam
Country Capital
France Paris
Nowrap

In a table that spans the entire width of a page, cells narrower than the widest cell tend to wrap. To keep an entire column from wrapping, use style=white-space:nowrap in a non-header cell on the longest/widest cell to affect the entire column.

Before:

Episode Date Summary
"The Journey Begins" January 1, 2010 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.
"When Episodes Attack" January 8, 2010 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.
"So Long" January 15, 2010 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.

After:

Episode Date Summary
"The Journey Begins" January 1, 2010 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.
"When Episodes Attack" January 8, 2010 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.
"So Long" January 15, 2010 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.


Tables with HTML attributes and CSS styles

CSS style attributes can be added with or without other HTML attributes

style="color:green;background-color:#ffffcc;" cellpadding="20" cellspacing="0" border="1"

Orange Apple
Bread Pie
Butter Ice cream
{| style="color:green;background-color:#ffffcc;" cellpadding="20" cellspacing="0" border="1"
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

Scrolling tables

Some tables contain enough data that they don't fit in the allotted space left to right. To create a table that scrolls left to right, put the table within div codes.

Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Heading 7
Heading 8
Heading 9
Heading 10
data 1
data 2
data 3
data 4
data 5
data 6
data 7
data 8
data 9
data 10


<div style="border: 2px solid rgb(221, 221, 221); overflow-y: hidden; overflow-x: auto; 
padding: 0.2em; width: 99%;" id="imageContainer">
{| cellspacing="1" cellpadding="10" border="1" width="1000"
|-
| Heading 1<br> 
| Heading 2<br> 
| Heading 3<br> 
| Heading 4<br> 
| Heading 5<br> 
| Heading 6<br> 
| Heading 7<br> 
| Heading 8<br> 
| Heading 9<br> 
| Heading 10<br>
|-
| data 1<br> 
| data 2<br> 
| data 3<br> 
| data 4<br> 
| data 5<br> 
| data 6<br> 
| data 7<br> 
| data 8<br> 
| data 9<br> 
| data 10<br> 
|}
</div>


Table with TH headings

TH (HTML table headings) can be created by using ! instead of |. Headings usually show up bold and centered by default.

Top headings

Each column

Yummy Yummier
Orange Apple
Bread Pie
Butter Ice cream
{| border="1" cellpadding="20" cellspacing="0"
!Yummy
!Yummier
|-
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

Colspan="2"

Yummies
Orange Apple
Bread Pie
Butter Ice cream
{| border="1" cellpadding="20" cellspacing="0"
! colspan="2"|Yummies
|-
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

Side headings

Default

Fruit Orange Apple
Dish Bread Pie
Complement Butter Ice cream
{| border="1" cellpadding="20" cellspacing="0"
!Fruit
|Orange
|Apple
|-
!Dish
|Bread
|Pie
|-
!Complement
|Butter
|Ice cream 
|}

Right justify

Right justified side headings can be done as follows

Fruit Orange Apple
Dish Bread Pie
Complement Butter Ice cream
{| border="1" cellpadding="20" cellspacing="0"
!align="right" |Fruit
|Orange
|Apple
|-
!align="right" |Dish
|Bread
|Pie
|-
!align="right" |Complement
|Butter
|Ice cream 
|}

Caption

A table caption can be added to the top of any table as follows

Food complements
Orange Apple
Bread Pie
Butter Ice cream
{| border="1" cellpadding="20" cellspacing="0"
|+Food complements
|-
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

Attributes can be added to the caption as follows

Food complements
Orange Apple
Bread Pie
Butter Ice cream
{| border="1" cellpadding="20" cellspacing="0"
|+align="bottom" style="color:#e76700;"|''Food complements''
|-
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}

Sorting

Tables can be made sortable by adding class="sortable"; for details see 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="sortable" border="1"
|+ '''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.

Table with H1, H2, H3 etc. headings

HTML H1, H2, H3, H4 etc. headings can be created the standard wiki markup way with ==equal== signs and must be on a line all by themselves to work.

Preview the whole table. If you click on an edit tab for a heading within a table, edit, and preview, the parent table will display erroneously broken because part of it will be missing.

Keep the heading hierarchy consistent with the rest of the page so that the table of contents at page top works correctly.

Yummiest

Orange Apple
Bread Pie
Butter Ice cream
{| border="3"  cellpadding="20" cellspacing="0"
|colspan="2"|
===Yummiest===
|-
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}



Tips

Help-content.png Questions?
Visit the Wiki Contributor Help Forum to receive help with contributing to the Wiki.

To merge or select cells press the 'CTRL' key while clicking in the cells.

A good way of formatting a table would be something of the form:

{| width="x%" border="1" cellspacing="0" style="margin: 1em auto;"

but you could also add:

cellpadding="4"

if you wanted more white space around the text within each cell.

Remember that you don't always have to set the width to 100%. This can be an irritation when the table just contains small amounts of data but is forced to stretch to fit the full screen:

left header right header
one two
three four

but

left header right header
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.

You can of course leave the width out and let the system decide, but this can result in tables being too narrow!

The best solution is 'trial-and-error'. Keep using the Show preview button and see what it looks like?

Caveat

Negative numbers

Negative value minus sign can break your table (it may display missing some values) if you start a cell on a new line with a negative number or a parameter that evaluates to a negative number (|-6) because that is the wiki markup for table row, not table cell. To avoid this, insert a space before the value (| -6) or use in-line cell markup (||-6).

See Also

Help-content.png Questions?
Visit the Wiki Contributor Help Forum to receive help with contributing to the Wiki.