User:42/SmTableGuide

42 notes
 * Obviously, the links would need to be re-done to allow the links to connect to any applicable wiki or metawiki sections. This should be minimal if even needed at all.
 * This is a very rough guide/idea presentation. The information from each section posted would (hopefully) be able to be posted directly from the actual metawiki table page.
 * The majority of the below list is needed in a table help page. Since most of the needed information has already been done by someone, the most sensible way would be to re-use that information and examples already given.


 * 1) Spreadsheet to wiki table format (this section would be not included/removed on GWW table help)
 * 2) Using the toolbar (this section would be edited to add GWW specific notes, or not included from metawiki and have GWW specific information instead)
 * 3) Pipe syntax tutorial NEEDED
 * 4) Examples NEEDED
 * 5) Simple example NEEDED
 * 6) Multiplication table NEEDED
 * 7) Color; scope of parameters NEEDED
 * 8) Width, height NEEDED
 * 9) Setting your column widths NEEDED
 * 10) Vertical alignment NEEDED
 * 11) Positioning NEEDED
 * 12) Mélange NEEDED
 * 13) Floating table NEEDED
 * 14) Nested tables NEEDED
 * 15) Combined use of COLSPAN and ROWSPAN NEEDED
 * 16) Centering tables NEEDED
 * 17) Setting parameters NEEDED
 * 18) Decimal point alignment (slightly more advanced, could possibly do without)
 * 19) Style classes (this section would most likely not be inluded; more information than the average person would need to use)
 * 20) Sorting NEEDED (used quite often in various tables, and for many different subjects)
 * 21) Row template  (unsure if this would be needed or not, could possibly do without this being on GWW table help)
 * 22) Conditional table row (not sure if this section would be needed or not, candidate for non-inlclusion on GWW table help)
 * 23) Other table syntax  (this entire section would be not included/removed on GWW table help)
 * 24) Comparison of table syntax (removed)
 * 25) Pipe syntax in terms of the HTML produced (this entire section would be not included/removed on GWW table help)
 * 26) Tables (removed)
 * 27) Rows (removed)
 * 28) Cells (removed)
 * 29) Headers (removed)
 * 30) Captions (removed)
 * 31) Displaying the table code which generates a table (this section not needed for basic table editors, needed more for someone making a how-to guide)
 * 32) Other alternatives to display table code (removed)
 * 33) Square monitors (would be not included/removed on GWW table help)
 * 34) Viewing tables in email and web pages outside Wikipedia (would be not included/removed on GWW table help)
 * 35) See also
 * 36) External links (would be not included/removed on GWW table help, references for excel to wiki)
 * 37) Links to other help pages (might keep, might not, depends on the needs I guess)

This page gives you information about syntax to build wiki-tables in MediaWiki.

Spreadsheet to wiki table format
(would remove/not include this section from GWW form) 

To convert from spreadsheets such as Gnumeric, MS Excel or OpenOffice.org Calc, see http://excel2wiki.net/.

Using the toolbar
(would keep this section, except possibly have our own GWW version/adaptation instead of straight content copy. else would add notes before or after to explain diffs between metawiki table and gww table) 

You can use the Mediawiki edit toolbar to create tables on Wikipedia, and some Wikimedia projects. It is helpful to generate the necessary codings. However, on many MediaWiki wikis (and by default) the table tool is not available.

Use the first button on the right of the toolbar to insert a table when editing a page.

By default, it includes the following text:

Pipe syntax tutorial
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: which is probably not what you want: However, the format modifier is useful:
 * The entire table is encased with curly brackets and a vertical bar character (a pipe). So use   to begin a table, and   to end it.  Each one needs to be on its own line:
 * An optional table caption is included with a line starting with a vertical bar and plus sign " " and the caption after it:
 * To start a new table row, type a vertical bar and a hyphen on its own line: " ". The codes for the cells in that row will start on the next line.
 * Type the codes for each table cell in the next row, starting with a bar:
 * 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:
 * If you use single bars, then what might appear to be the first cell is in fact a format modifier applied to the cell, and the rest of your "cells" will be merged into one:

Just remember: no more than 2 single pipes on a line!

The final table would display like this:  The table parameters and cell parameters are the same as in HTML, see  and Table (HTML). However, the,  ,  ,  , and   elements are currently not supported in MediaWiki.
 * a row of column headings is identified by using "!" instead of "|", and using "!!" instead of "||". Header cells typically render differently from regular cells, depending on the browser.  They are often rendered in a bold font and centered.
 * the first cell of a row is identified as row heading by starting the line with "!" instead of "|", and starting subsequent data cells on a new line.
 * Optional parameters can modify the behavior of cells, rows, or the entire table. For instance, a border could be added to the table:

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. An "image" in the form of a table is much more convenient to edit than an uploaded image.

Each row must have the same number of cells as the other rows, so that the number of columns in the table remains consistent. For empty cells, use the non-breaking space  as content to ensure that the cells are displayed. To show a visible pipe in a cell, use &lt;nowiki>|&lt;/nowiki> or &amp;#124;.

With colspan and rowspan cells can span several columns or rows, see the M&#233;lange example below. However, this has the disadvantage that sorting does not work properly anymore.

Simple example
Both of these generate the same output. Choose a style based on the number of cells in each row and the total text inside each cell.

Wiki markup 



What it looks like in your browser 

Multiplication table
Wiki markup 

What it looks like in your browser (see: Help:User_style) 

Color; scope of parameters
See also: Wiki color formatting help

Two ways of specifying color of text and background for a single cell are as follows. The first form is preferred:

Wiki markup 

What it looks like in your browser 

Note: The  is deprecated.

Like other parameters, colors can also be specified for a whole row or the whole table; parameters for a row override the value for the table, and those for a cell override those for a row:

Wiki markup 

What it looks like in your browser 

To make the table blend in with the background, use  or. (Warning:, does not work with some browsers, including IE6!)

See : style, background, list of colors, web colors

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 

What it looks like in your browser 

Note that inline CSS  has no effect with some browsers. If compatibility is important, equivalent older constructs like  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;">

<blockquote style="background: white; border: 1px solid black; padding: 1em;">

To set column widths in a table without headers, specify the width in the first cell for each column, like this:

<blockquote style="background: white; border: 1px solid black; padding: 1em;">

<blockquote style="background: white; border: 1px solid black; padding: 1em;">

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

Vertical alignment
By default data in tables is vertically centrally aligned, which results in odd-looking layouts like this:

<blockquote style="background: white; border: 1px solid black; padding: 1em;">

To fix this, apply the valign="top" attribute to the rows (unfortunately it seems to be necessary to apply this individually to every single row). For example:

<blockquote style="background: white; border: 1px solid black; padding: 1em;">

<blockquote style="background: white; border: 1px solid black; padding: 1em;">

Positioning
One can position the table itself, and all contents in a row, and contents in a cell, but not with a single parameter for all contents in the table, see m:Template talk:Table demo. Do not, under any circumstances, use "float" to position a table. It will break page rendering at large font sizes.

M&eacute;lange
Here's a more advanced example, showing some more options available for making up tables. Note, however, that with use of the colspan and rowspan attributes, sorting does not work properly anymore.

You can play with these settings in your own table to see what effect they have. Not all of these techniques may be appropriate in all cases; just because you can add colored backgrounds, for example, doesn't mean it's always a good idea. Try to keep the markup in your tables relatively simple -- remember, other people are going to be editing the article too! This example should give you an idea of what is possible, though.

Wiki markup <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em; overflow:auto;">

What it looks like in your browser <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

Floating table
Wiki markup <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...

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 <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...

Note the floating table to the right.

This paragraph is after the table. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation...

Nested tables
Five different (blue) tables are shown nested inside the cells of a table. Automatically the two tables |A| and |B|B| are vertically aligned instead of the usual side by side of text characters in a cell. "float" is used to fix each of tables |C| and |D| to their own position within one cell of the table. This may be used for charts and schemes. Nested tables must start on a new line.

Wiki markup <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;"><p style="border: 1px dashed #2f6fab; background-color: #f9f9f9;"> </tt>

What it looks like in your browser <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

Combined use of COLSPAN and ROWSPAN
Wiki markup <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

What it looks like in your browser <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

Note that using  for cell G combined with   for cell F to get another row below G and F won't work, because all (implicit) cells would be empty. Likewise complete columns are not displayed if all their cells are empty. Borders between non-empty and empty cells might be also not displayed (depending on the browser), use  to fill an empty cell with dummy content.

Centering tables
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" </tt>

Wiki markup <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

What it looks like in your browser <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

Setting parameters
At the start of a cell, add your parameter followed by a single pipe. For example 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;">

What it looks like in your browser <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

Decimal point alignment
A simple and reliable way to achieve decimal point alignment is to use Template:0, assuming it has been defined along the following lines:

See wikipedia:Template:0 for further details.

Another 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;">

What it looks like in your browser <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

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;">

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" width="50%"






 * }

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
(could more than likely remove this code, not that much would be useful for the general wiki user) 


 * See also Help:User style.

In the first line of table code, after the "{|", instead of specifying a style directly one can also specify a CSS class. The style for this class can be specified in various ways:
 * in the software itself, per skin (for example the class sortable, used at wikibits.js)
 * collectively for all users of one wiki in MediaWiki:Common.css (for example, on this and some other projects there is the class wikitable)
 * separately per skin in MediaWiki:Monobook.css etc.
 * individually on one wiki in a user subpage
 * individually, but jointly for tables of the class concerned on all web pages, on the local computer of the user.

Instead of remembering table parameters, you just include an appropriate style class after the. This helps keep table formatting consistent, and can allow a single change to the class to fix a problem or enhance the look of all the tables that are using it at once. For instance, this:

simply by replacing inline CSS for the table by. 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 <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

What it looks like in your browser <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

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  instead of "font-size:120%", or Wiki markup like   instead of "font-style:italic".

Sorting
Tables can be made sortable by adding ; 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 <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

What it looks like in your browser <blockquote style="background: white; border: 1px solid rgb(153, 153, 153); padding: 1em;">

Row template
Regardless of whether wikitable format or HTML is used, the wikitext of the rows within a table, and sometimes even within a collection of tables, has much in common, e.g.: In that case it can be useful to create a template that produces the syntax for a table row, with the data as parameters. This can have many advantages:
 * the basic code for a table row
 * code for color, alignment, and sorting mode
 * fixed texts such as units
 * special formats for sorting
 * easily changing the order of columns, or removing a column
 * easily adding a new column if many elements of the new column are left blank (if the column is inserted and the existing fields are unnamed, use a named parameter for the new field to avoid adding blank parameter values to many template calls)
 * computing fields from other fields, e.g. population density from population and area
 * duplicating content and providing span tags with "display:none" for the purpose of having one format for sorting and another for display
 * easy specification of a format for a whole column, such as color and alignment

Example:

Using gives:

Conditional table row
(would possibly remove/not include this section from GWW form)  A pipe character for a table row may be desired as part of a parameter value in the call of a template or parser function (in particular, it can be in code made optional using ParserFunctions). However, expansion of templates and parser functions happens before interpretation of table syntax. This causes a pipe character in a parameter value to be interpreted as a separator between parameter definitions. To avoid this, these pipe characters are generated with a special ; see.

If one tries to use as conditional code for a conditional row " | - | text " the problem is that the last is ignored:

ac

gives "ac".

Thus, depending on whether there is a after the condition, we could have a newline too many or too few.

This is solved by using the technique of Help:Newlines and spaces:

gives

Each condition is used at two places. To avoid having it twice in the wikitext, it can be made a template parameter for a template containing the code for conditionally producing a table row, e.g., Conditional template call with newline, and in this case

Other table syntax
(would possibly remove/not include this section from GWW form)  Other types of table syntax that MediaWiki supports:
 * 1) XHTML
 * 2) HTML &amp; wiki-  syntax (Do not use)

All three are supported by MediaWiki and create (currently) valid HTML output, but the pipe syntax is the simplest. Also, HTML &amp; wiki-  syntax (i.e., unclosed   and   tags) will not necessarily remain browser-supported in the upcoming future, especially on handheld internet-accessible devices.

See also Table (HTML), HTML element#Tables. Note however that the,  ,  ,  , and   elements are currently not supported in MediaWiki.

Comparison of table syntax
Sample table

Pros
 * Can be previewed/debugged with any XHTML editor
 * Can be formatted for easier reading
 * Well-known
 * Newlines not needed, but to some extent allowed
 * No characters like "|" which can collide with template and parser function syntax
 * Harder to shoot yourself in the foot with than HTML, since proper nesting and tag closure are enforced


 * Can be previewed/debugged with any HTML editor
 * Can be formatted for easier reading
 * Well-known
 * Takes less space than XHTML
 * Newlines not needed, but to some extent allowed
 * No characters like "|" which can collide with template and parser function syntax


 * Easy to write
 * Easy to read
 * Takes little space

Cons
 * Tedious
 * Takes a lot of space
 * Difficult to read quickly


 * May not have browser support in future


 * 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
 * Assigning to a template parameter a value containing "|" requires Template:!
 * Sensitive to newlines; since these are automatically stripped from templates and parameters in some cases, special techniques are sometimes needed to avoid this, see Help:Newlines and spaces

XHTML HTML &amp; Wiki-td Wiki-pipe

See also Template talk:For.

Pipe syntax in terms of the HTML produced
(would remove/not include this section from GWW form)  The pipe syntax, developed by Magnus Manske, substitutes pipes ( | ) for HTML. There is an on-line script which converts html tables to pipe syntax tables.

The pipes must start at the beginning of a new line, except when separating parameters from content or when using  to separate cells on a single line. The parameters are optional.

Tables
A table is defined by which equals

For this:

Viewing tables in email and web pages outside Wikipedia
(would remove/not include this section from GWW form) 

Tables are an essential part of presenting information in an easily understandable way. Everything on Wikipedia can be copied elsewhere, and it is encouraged. But Wikipedia tables oftentimes lose their borders when pasted into web pages, blogs, or email.

The Wikipedia table button produces this:

Note the borders around all the cells, and the whole table. Copy and paste the table into your email, and the borders disappear. This makes the table look something like this below. It is much less understandable.

This is easily fixed. If you want and expect your table to be passed around in email, blogs, and other web pages, then add


 * border="1"

somewhere in the first line of your chart wikicode. For example;

The table will look the same on the Wikipedia page, but it will now also have borders when copied into email, blogs, and other web pages. Bloggers and webmasters will not have to add CSS code in order to see the chart in a format with basic borders.