Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Help:Table

From Wikipedia, the free encyclopedia
How to create and use tables in markup
This help page is ahow-to guide.
It explains concepts or processes used by the Wikipedia community. It is not one ofWikipedia's policies or guidelines, and may reflect varying levels ofconsensus.
Are you new here? There is a simplified version of this page atHelp:Introduction to tables.
Wikitext

Atable is an arrangement of columns and rows that organizes and positions data or images. Tables can be created on Wikipedia pages using specialwikitext syntax, orHTML syntax, and many different styles and tricks can be used to customise them.

Tools

[edit]

Source mode toolbar

[edit]
Vector toolbar – default. Table icon is circled.
Monobook toolbar. Table icon is on the right end.

To automatically insert a table, click or (Insert a table) on theedit toolbar. In the Vector toolbar the table icon is in the "Advanced" menu.

The following wikitext is inserted whenInsert a table is clicked.

{|class="wikitable"|+ Caption text|-! Header text!! Header text!! Header text|-| Example|| Example|| Example|-| Example|| Example|| Example|-| Example|| Example|| Example|}

The sample text ("Header text" or "Example") is intended to be replaced with actual data. Row numbers (1-3) and column letters (A-C) have been substituted below to help visualization.

Wikitext

{|class="wikitable"|+ Caption text|-! Header A!! Header B!! Header C|-| row 1 A|| row 1 B|| row 1 C|-| row 2 A|| row 2 B|| row 2 C|-| row 3 A|| row 3 B|| row 3 C|}

Produces:

Caption text
Header AHeader BHeader C
row 1 Arow 1 Brow 1 C
row 2 Arow 2 Brow 2 C
row 3 Arow 3 Brow 3 C

You can fill in the table while in source mode. Or use the visual editor (VE). To create more complex table structures in source mode with cells that span multiple rows or columns, see§ Colspan and rowspan.

Visual editor

[edit]
See:Help:Tables and VisualEditor. And:Help:Creating tables#Tables and visual editor.
Most table editing is easier in thevisual editor than in the wikitext source editor. Find the pencil icon in the toolbar to toggle between wikitext source editing and visual editing.

With thevisual editor (VE) you directly fill in the cells without having to go through wikitext. VE makes it easy to add, remove, and rearrange/reorder rows or columns. In VE this is what shows up when clicking the table icon (in the "Insert" menu):

For more complex table structures, the visual editor offers cell-merging operations; see detailshere.

In addition, it is usually possible to add or import a table that exists elsewhere (e.g., in a spreadsheet, on another website) directly into the visual editor by:

  • dragging and dropping a.csv file into the visual editor, or
  • selecting, copying, and pasting the table into the visual editor.

Using other tools

[edit]
See also:Help:Creating tables § Spreadsheet/database tables to wikitables, andWikipedia:Tools § Importing (converting) content to Wikipedia (MediaWiki) format

Other tools, such as those used to create wiki tables from Excel, can be used to create wikitable markup from spreadsheet and database tables. See§ External links for a list of some.

Table basics

[edit]

Tables can be added to articles and other pages using either standardHTML table elements, or with specialwikicode markup developed just to facilitate creating tables without a knowledge of HTML.

Markup

[edit]
See also:Help:Basic table markup
Overview of basic table markup
Table elementWikitextRequiredUsage notes
Table start{|RequiredNote:{| Entire table goes here|}
Caption|+OptionalOnly between table start and first table row.
Row separator|-RequiredPlaced on its own line, in betweenrows
Optionalbefore the first row, where it may be omitted.
Header cell! or!!OptionalA new row, and so its first cell, starts on a new line. Row and column header cells begin with one (exclamation) mark (!). Consecutive table header cells may be added on the same line, separated by double exclamation marks (!!) – or start on new lines, each with its own single mark.
Data cell| or||OptionalConsecutive table data cells may be added on the same line, separated by double (pipeline) marks (||) – or start on new lines, each with their own single (pipeline) marks (|).
The pipeline symbol is also used to separate pertainingHTML attributes from the cell or caption contents that follow.
Table end|}Required
  • The above marks muststart on a new line, except the double marks (|| and!!) for optionally adding consecutive cells to a single line.
  • Blank spaces at the beginning of a line are ignored.
  • Content may either follow its cell mark on the same line (after any optional HTML attributes); or on lines below the cell mark (beware of undesired paragraphs though). Content that uses wiki markup that itself needs to start on a new line, such as with lists, headings, or nested tables, must be put on its own new line.
  • To insert apipe character (|) into a table caption or cell, use the<nowiki>|</nowiki> escaping markup.

HTML attributes

[edit]

Each mark, except table end (|}), optionally accepts one or moreattributes. Attributes must be on the same line as the mark.

  • Cells andcaptions (| or||,! or!!, and|+) holdcontent—separate any attribute from its content with a single pipe (|), with attributes preceding content.
  • Table androw marks ({| and|-) do not directly hold content. Donot add a pipe (|) after any attributes.

Commonly included attributes with table scope include:class, for exampleclass="wikitable"; orstyle forCSS styling. Other attributes have row- or column scope, e.g.,scope, to indicate row or column header cells;rowspan, to extend cells by more than one row; andcolspan, to extend cells by more than one column.

Wikicode syntax tutorial

[edit]
Main page:Help:Basic table markup
For a history of the development of wikicode table syntax, see/History of pipe syntax development.

A table may be created entirely inwikicode using special table markupdeveloped for the purpose. No knowledge of HTML is required.

Begin and end delimiters

[edit]

Use{| to begin a table, and|} to end it. Each one needs to be on its own line:

{|  caption/rows go here|}

Optional parameters likeclass may be placed on the Begin-table delimiter line. See§ Class below.

Caption

[edit]

An optionaltablecaption is included with a line starting with a vertical bar and plus sign "|+" and the caption after it:

{||+ The table's caption  rows go here|}

Row start

[edit]

To start a newtablerow, type a vertical bar and ahyphen on its own line: "|-". The codes for the cells in that row start on the next line.

{||+ The table's caption|-  row 1 cells go here|-  row 2 cells go here|}

For details about rows, see§ Row operations below.

Cells

[edit]

Type the codes for eachtable cell in the next row, starting with a bar:

{||+ The table's caption|-| Row 1 cell 1| Row 1 cell 2|-| Row 2 cell 1| Row 2 cell 2|}

Cells can be separated with either a new line and a single bar, or by a double bar "||" on the same line. Both produce the same output:

Wikitext

{||+ The table's caption|-|Cell 1|| Cell 2|| Cell 3|-|Cell A|Cell B|Cell C|-|Cell x|Cell y||Cell z|}

Produces

The table's caption
Cell 1Cell 2Cell 3
Cell ACell BCell C
Cell xCell yCell z

For details about table cells, see§ Cell operations below.

Optional parameters

[edit]

Optionalparameters can modify the display and styling of cells, rows, or the entire table. The simplest way to add styling is to set thewikitableCSS class, which in Wikipedia'sexternal style sheet is defined to apply a gray color scheme and cell borders to tables using it:

Wikitext

{|class=wikitable|+ The table's caption! Column header 1! Column header 2! Column header 3|-! Row header 1| Cell 2|| Cell 3|-! Row header A| Cell B| Cell C|}

Produces

The table's caption
Column header 1Column header 2Column header 3
Row header 1Cell 2Cell 3
Row header ACell BCell C

The table parameters and cell parameters are the same as inHTML, see http://www.w3.org/TR/html401/struct/tables.html#edef-TABLE andTable (HTML). However, the<thead>,<tbody>,<tfoot>,<colgroup>, and<col> elements are currentlynot supported in MediaWiki, as of December 2021[update].

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, likemeta:Template talk:Square 8x8 pentomino example. An "image" in the form of a table is much more convenient to edit than an uploaded image.

If all the cells in a row are empty the cells still show up. If the header cell is also empty for that row all the cells show up, but they are narrow. That can be fixed with a simple <br> in one of the cells. That is what is done here:

{{sort under}} is simpler for putting the sorting arrows below the header text in order to narrow a table.

Withcolspan androwspan cells can span several columns or rows;(see§ Colspan and rowspan, below)

Displaying a pipe character

[edit]

Displaying apipe character as part of the text of a table cell requires a workaround. See§ Rendering the pipe.

Scope

[edit]

Column headers are identified by! scope="col" | instead of|.Row headers are identified by! scope="row" | instead of|. Each header cell should be on a separate line in the wiki-markup. Thescope="col" andscope="row" markup should be used for column and row headers in all data tables because it explicitly associates the header with the corresponding cells, which helps ensure a consistent experience for screen readers. The Manual of Stylerequires the use of scope for column and row headers.

Forcomplex tables, when a header spans two columns or rows, use! scope="colgroup" colspan="2" | or! scope="rowgroup" rowspan="2" | respectively to clearly identify the header as a column header of two columns or a row header of two rows. When headers are unclear, this can cause accessibility issues; therefore, useid= to set a unique value without spaces on each header, then reference the id(s) on the data cells that have unclear headers usingheaders= with a space separating each id.

Header cells typically render differently from regular cells, depending on the browser. They are often rendered in a bold font and centered. If this rendering is not desired from an aesthetic point of view, the table can be styled with the "plainrowheaders" class which left-aligns the row headers and removes the bolding. Left-alignment of row headers only occurs ifclass=wikitable andscope=row are both used.

A typical example may be marked up like this:

Wikitext

{|class="wikitable plainrowheaders"|+ The table's caption !scope=col| Column header 1 !scope=col| Column header 2 !scope=col| Column header 3|- !scope=row| Row header 1 | Cell 2|| Cell 3|- !scope=row| Row header A | Cell B|| Cell C|}

Produces

The table's caption
Column header 1Column header 2Column header 3
Row header 1Cell 2Cell 3
Row header ACell BCell C

Examples

[edit]

Minimalist table

[edit]

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

Wikitext

{||-| A| B|-| C| D|}
{||-| A|| B|-| C|| D|}

Produces (without borders).

AB
CD

Multiplication table

[edit]

In this exampleclass="wikitable" is used to style the table with Wikipedia's external style sheet for tables. It adds borders, background shading, and bold header text.

Wikitext

{|class=wikitablestyle="text-align: center;"|+ Multiplication table|-! ×! 1! 2! 3|-! 1| 1|| 2|| 3|-! 2| 2|| 4|| 6|}

Produces

Multiplication table
×123
1123
2246

Whole table operations

[edit]

Class

[edit]

One or more classes may be added to the§ Begin-table delimiter line at the top of the table, and may be used to supply predefined style to the table. The wikicode tableclass attributecorresponds directly to the "class"attribute of the HTML<table> element. To add multiple classes to a table, place them all on the same line, embedded in double quotes and separated by a space:

{|class="wikitable sortable mw-collapsible"

Some predefined classes are:

A sortable wikitable
breedhtwt
Labrador Retriever2370
French Bulldog1225
German Shepherd2778
Golden Retriever2371
English Bulldog1445
  • wikitable – provides column headers with bold font on shaded background, and other common style. Seehere for details. This class should be used for almost all tables, unless there is a reason not to.
  • sortable – adds up & down icons to column headers which enable sorting the table on a given column. Seesortable tables.
  • mw-collapsible – Seecollapsible tables.[note 1]
  • plainrowheaders – applies left-aligned and normal-weight formatting of row headers. SeeTable header layout. Must be placed afterwikitable if they both appear in the class declaration.
  • floatright – same as applyingstyle="float:right; clear:right; margin-left:8px" to the entire table
  • floatleft – same as applyingstyle="float:left; clear:left; margin-right:8px" to the entire table

Note:Template:Table may also be used to apply classes to the§ Begin-table delimiter line.

Captions and summaries

[edit]
Further information:Wikipedia:Manual of Style/Accessibility/Data tables tutorial § Proper table captions and summaries

Explicit tablecaptions (ortitles) are recommended for data tables as a best practice; the Wikipedia Manual of Styleconsiders them a high priority for accessibility reasons (screen readers), as a caption is explicitly associated with the table, unlike a normal wikitext heading or introductory sentence. All data tables on Wikipedia require captions. A caption is provided with the|+ markup, similar to a table row (|-), but it does not contain any cells, and is not within the table border. Captions are always displayed, appearing as a title centered (in most browsers), above the table. A caption can be styled (with inline, not block, CSS), and may include wikilinks, reference citations, etc.

Many article editors dislike table captions when the table is directly below, or not far away from, a similar article heading. Butscreen reader users still need a table caption to quickly browse from table to table. In this case use the popular{{sro}} template:Template:Screen reader-only. Add the template to the table caption, and then only screen reader users will see it. Example:

|+{{sro|Table caption}}

For current table caption and summary guidelines see the w3.org page:Caption & Summary, in Tables Tutorial.Web Accessibility Initiative (WAI). The summary info in the paragraph below is out of date:

Asummary provides an overview of the data of a table for text and audio browsers, and does not normally display in graphical browsers. The summary (also a high Manual of Style priority for tables) is a synopsis of content, and does not repeat the caption text; think of it as analogous to an image'salt description. A summary is added withsummary="Summary text here.", on the same line as the{| that opened the table, along with anyclass= and other parameters for the table as a whole.Thesummary= attribute is, however,obsolete in HTML 5.

Wiki markup example showing left-aligned caption with a source citation:

{|class=wikitable|+style="text-align: left;"| Data reported for 2014–2015, by region<ref name="Garcia 2005"/>|-!scope=col| Year!!scope=col| Africa!!scope=col| Americas!!scope=col| Asia & Pacific!!scope=col| Europe|-!scope=row| 2014| 2,300|| 8,950||''9,325''|| 4,200|-!scope=row| 2015| 2,725||''9,200''|| 8,850|| 4,775|}

Produces

Data reported for 2014–2015, by region[99]
YearAfricaAmericasAsia & PacificEurope
20142,3008,9509,3254,200
20152,7259,2008,8504,775

Colspan and rowspan

[edit]

It is possible to create cells that stretch over two or more columns. For this, one uses|colspan=n |content.Similarly, one can create cells that stretch over two or more rows. This requires|rowspan=m |content. In the table code, one mustleave out the cells that are covered by such a span. The resulting column- and row-counting must fit.

Wikitext

{|class=wikitablestyle="text-align: center;"!col1!col2!col3!col4|-!row1|colspan=2| A<!-- column counting: cell 'B' can not exist -->|C|-!row2|AA|BB|CC|-!row3|AAA|rowspan=2| BBB|CCC|-!row4|AAAA<!-- row counting: cell 'BBBB' can not exist -->|CCCC|}

Produces

col1col2col3col4
row1AC
row2AABBCC
row3AAABBBCCC
row4AAAACCCC

In the code, the cell| colspan="2" | A spans two columns. In the next column,a cell expected to contain "B" does not exist.

Similar: in the code, cell| rowspan="2" | BBB spans two rows.A cell expected to contain "BBBB" does not exist.

Wikitext

{|class=wikitable|-! Column 1!! Column 2!! Column 3|-|rowspan=2| A|colspan=2style="text-align: center;"| B<!-- column 3 of this row occupied by cell B (which is to the left) -->|-<!-- column 1 of this row occupied by cell A (above) -->| C| D|-| E|rowspan=2colspan=2style="text-align: center;"| F<!-- column 3 of this row occupied by cell F (to the left) -->|-| G<!-- columns 2 and 3 of this row occupied by cell F (above) -->|-|colspan=3style="text-align: center;"| H<!-- columns 2 and 3 of this row occupied by cell H (to the left) -->|}

Produces

Column 1Column 2Column 3
AB
CD
EF
G
H

Usingrowspan=2 for cellG combined withrowspan=3 for cellF to get another row belowG andF won't work, because all (implicit) cells would be empty.

Below is the same table with the order of the declared rows and cells shown in parentheses. The uses ofrowspan andcolspan are also shown.

Wikitext

{|class=wikitable|-! Column 1<br>(row 1 cell 1)!! Column 2<br>(row 1 cell 2)!! Column 3<br>(row 1 cell 3)|-|rowspan=2| A<br>(row 2 cell 1)<br><code>rowspan=2</code>|colspan=2style="text-align: center;"| B<br>(row 2 cell 2)<br><code>colspan=2</code>|-| C<br>(row 3 cell 1)<!-- column 1 occupied by cell A -->| D<br>(row 3 cell 2)|-| E<br>(row 4 cell 1)|rowspan=2colspan=2style="text-align: center;"|F<br>(row 4 cell 2)<br><code>rowspan=2 colspan=2</code>|-| G<br>(row 5 cell 1)<!-- column 2+3 occupied by cell F -->|-|colspan=3style="text-align: center;"| H<br>(row 6 cell 1)<br><code>colspan=3</code>|}

Produces

Column 1
(row 1 cell 1)
Column 2
(row 1 cell 2)
Column 3
(row 1 cell 3)
A
(row 2 cell 1)
rowspan=2
B
(row 2 cell 2)
colspan=2
C
(row 3 cell 1)
D
(row 3 cell 2)
E
(row 4 cell 1)
F
(row 4 cell 2)
rowspan=2 colspan=2
G
(row 5 cell 1)
H
(row 6 cell 1)
colspan=3

Although cellC is in column 2,C is the 1st cell declared in row 3, because column 1 is occupied by cellA, which was declared in row 2. CellG is the only cell declared in row 5, because cellF occupies the other columns but was declared in row 4.

Table style

[edit]

Astyle element may be added to apply to the entire table, to all the cells§ in a row, or just to individual cells in the table. Adding a style to a column requires a template such as{{table alignment}} (for horizontal alignment of text).

To add style to the entire table, add thestyle element to the§ Begin-table delimiter line at the top of the table. in some cases, it may be better to use the style encapsulated in one of the predefined classes; see§ Class.

Horizontal text alignment

[edit]
Further information:Help:Table/Advanced § Horizontal alignment in cells

Text alignment (right/center/left) for the whole table (except the headers in a table usingclass=wikitable) can be done at the top line of the table wikitext:

{|class=wikitablestyle=text-align:right; ...|}

Text alignment for a column can be done with{{table alignment}}.

Height

[edit]

The height of the whole table can be specified using standard CSS style properties on the§ start table indicator line:

{|class=wikitablestyle=height:14em;  . . .|}

You may also specify the§ height of individual rows, and if they add up to more than the table height you specified or if word wrapping increases row height, the table height you specified will be ignored and the table height increased as needed to accommodate all the rows (except on mobile where the bottom of the table will be cut off).

Borders

[edit]

Note:Wikipedia:HTML 5#Table attributes. CSS to replace obsolete attributes for borders, padding, spacing, etc.

Add a border around a table using the CSS propertyborder:thickness style color;, for exampleborder:3px dashed red. This example uses a solid (non-dashed) gray border that is one pixel wide:

Wikitext

{|style="border-spacing: 2px; border: 1px solid darkgray;"!style="width: 140px;"| Left!style="width: 150px;"| Center!style="width: 130px;"| Right|-|[[File:Starred.svg|120px| center]]|[[File:Star full.svg|120px| center]]|[[File:Stargreen.svg|120px| center]]|-style="text-align: center;"|Red star|| Orange star|| Green star|}

Produces

LeftCenterRight
Red starOrange starGreen star

Note the bottom-row texts are centered bystyle="text-align: center;" to match the centering of the stars in their cells.

As long as theFile: specs omit the parameter|thumb they don't show the caption lines in the table (only during mouse-over). The border colordarkgray matches typical tables or infoboxes in articles; however, it could be any color name (as instyle="border: 1px solid darkgreen;") or use ahex-color (such as:#DDCCBB).

Border-collapse: conflicting or double borders

[edit]

Wikitext

{|border=1|-| A|| B|| C|-| D|| E|| F|}

Produces

ABC
DEF

If all cells have the same border color, the resulting double borders may not be wanted; add theborder-collapse: collapse; CSS property on the table opening tag to reduce them to single ones (cellspacing=... isobsolete).

Additionally, theW3Callows the use of the otherwise obsoleteborder= attribute on the table root ({|) if its value is "1". This adds a one-pixel border, in the default color, to the table and all of its cells at once:

Using theborder-collapse property to combine the double borders, as described above:

Wikitext

{|border=1style="border-collapse: collapse;"|-| A|| B|| C|-| D|| E|| F|}

Produces

ABC
DEF

Float table left or right

[edit]

Two table classesfloatleft andfloatright (case sensitive) help floating the table and adjusting table margins so that they do not stick to the text.floatleft floats the table to the left and adjusts right margin.floatright does the opposite. Example:

Wikitext

This paragraph is before the table.[[File:Starred.svg|120px|right]]{|class="wikitable floatleft"|+ Caption text|-! Header A!! Header B!! Header C|-| row 1 A|| row 1 B|| row 1 C|-| row 2 A|| row 2 B|| row 2 C|}{|class="wikitable floatright"|+ Caption text|-! Header A!! Header B!! Header C|-| row 1 A|| row 1 B|| row 1 C|-| row 2 A|| row 2 B|| row 2 C|}... Lorem text after table

As it appears in a browser:

This paragraph is before the table.

Caption text
Header AHeader BHeader C
row 1 Arow 1 Brow 1 C
row 2 Arow 2 Brow 2 C
Caption text
Header AHeader BHeader C
row 1 Arow 1 Brow 1 C
row 2 Arow 2 Brow 2 C

Vestibulum sapien nisl, ornare auctor, consectetuer quis, posuere tristique, odio. Fusce ultrices ullamcorper odio. Ut augue nulla, interdum at, adipiscing non, tristique eget, neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut pede est, condimentum id, scelerisque ac, malesuada non, quam. Proin eu ligula ac sapien suscipit blandit. Suspendisse euismod. Ut accumsan, neque id gravida luctus, arcu pede sodales felis, vel blandit massa arcu eget ligula. Aenean sed turpis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec sem eros, ornare ut, commodo eu, tempor nec, risus. Donec laoreet dapibus ligula. Praesent orci leo, bibendum nec, ornare et, nonummy in, elit. Donec interdum feugiat leo. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque feugiat ullamcorper ipsum. Donec convallis tincidunt urna.


Alternatively, you can useCSS to get the same result:
{|
{|

This paragraph is before the table.

Caption text
Header AHeader BHeader C
row 1 Arow 1 Brow 1 C
row 2 Arow 2 Brow 2 C
Caption text
Header AHeader BHeader C
row 1 Arow 1 Brow 1 C
row 2 Arow 2 Brow 2 C

Vestibulum sapien nisl, ornare auctor, consectetuer quis, posuere tristique, odio. Fusce ultrices ullamcorper odio. Ut augue nulla, interdum at, adipiscing non, tristique eget, neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut pede est, condimentum id, scelerisque ac, malesuada non, quam. Proin eu ligula ac sapien suscipit blandit. Suspendisse euismod. Ut accumsan, neque id gravida luctus, arcu pede sodales felis, vel blandit massa arcu eget ligula. Aenean sed turpis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec sem eros, ornare ut, commodo eu, tempor nec, risus. Donec laoreet dapibus ligula. Praesent orci leo, bibendum nec, ornare et, nonummy in, elit. Donec interdum feugiat leo. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque feugiat ullamcorper ipsum. Donec convallis tincidunt urna.

Centering tables

[edit]
Shortcut

To center a table horizontally, use stylemargin: auto, which applies to the left and right margins. Text does not flow around centered tables as it does for floated tables; that is, no text appears to either side:

Wikitext

Text before table...{|class="wikitable"style="margin: auto; border: none;"|+ Centered table|-!scope="col"| Duis!scope="col"| aute!scope="col"| irure|-| dolor|| in reprehenderit|| in voluptate velit|-| esse cillum dolore|| eu fugiat nulla|| pariatur.|}...text after table

As it appears in a browser:

Text before table...

Centered table
Duisauteirure
dolorin reprehenderitin voluptate velit
esse cillum doloreeu fugiat nullapariatur.

...text after table.

Stylemargin:auto may be combined with top and bottom margin in the standard way for CSS, e.g.style="margin:1em auto" defines top and bottom margins of 1em, and automatic (centered) left and right margins.

Tip: For Android Chrome, use:

{|[note 2]

Note:align="center" isdeprecated in HTML5, and does not work well in Mediawiki software. For example, it will not override the left alignment of tables viaclass=wikitable.

Static ('sticky') headers

[edit]

Headers can be frozen so they're always at the top (or left) as one scrolls through a large table. See{{Sticky header}} and{{Sticky table start}}.

Nested tables

[edit]
Note: because they causeaccessibility issues, header cells in nested tables should be avoided whenever possible. For accessibility, any complicated table must be carefully designed to maintain normal flow, i.e. the ordering of content in the page code should match the order in which it is to be presented.

Nesting data tables with header cells makes it difficult for assistivescreen readers to parse them sensibly.

Editors sometimes use headerless tables as an aid to content layout, especially where it is easier than the equivalent use of divs and CSS styling. For complex layouts,rowspan andcolspan may be used, but again it is sometimes simpler and more maintainable to use nested tables.

Nested tables must start on a new line.

In the following example, five different tables are shown nested inside the cells of a sixth, main table. None has any header cells. 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 schematics.

αcell2
NESTED
TABLE
the original table again
A
BB
C
D

Wikitext:

{|style="border: 1px solid black;"|style="border: 1px solid black;"|&alpha;|style="border: 1px solid black; text-align:center;"| cell2{|style="border: 2px solid black; background: #ffffcc;"<!-- The nested table must be on a new line -->|style="border: 2px solid darkgray;"| NESTED|-|style="border: 2px solid darkgray;"| TABLE|}|style="border: 1px solid black; vertical-align: bottom;"| the original table again|style="border: 1px solid black; width:100px"|{|style="border: 2px solid black; background: #ffffcc"|style="border: 2px solid darkgray;"| A|}{|style="border: 2px solid black; background: #ffffcc"|style="border: 2px solid darkgray;"| B|style="border: 2px solid darkgray;"| B|}|style="border: 1px solid black; width: 50px"|{|style="border: 2px solid black; background:#ffffcc; float:left"|style="border: 2px solid darkgray;"| C|}{|style="border: 2px solid black; background:#ffffcc; float:right"|style="border: 2px solid darkgray;"| D|}|}

Column operations

[edit]

There are column and cell operations for width. SeeHelp:Width of tables, columns, and cells.

There are also column, cell, and table operations for text alignment (right, left and center alignment). SeeHelp:Table/Advanced#Column alignment. It is part of a much larger section of info on aligning text in individual table cells, or the table as a whole.

See also:{{table alignment}}. This template allows easy aligning of text in a column, or multiple columns.

To insert, remove, or rearrange whole columns, seeHelp:Creating tables#Move/delete row/column. This is much faster and easier to do in the visual editor than in the wikitext editor.

To sort some or all columns in a table seeHelp:Sortable tables.

Width

[edit]

This is a complex subject. Please see the main page:

Row operations

[edit]

Table rows are added after the§ table start indicator, and after any optional§ whole table markup such as a caption, table summary, or§ column scope attributes.

Starting a new row

[edit]

To start a newtablerow, type a vertical bar and ahyphen on its own line: "|-". The codes for the cells in that row start on the next line. Anid for§ anchoring in-links, and§ row style may be included on the same line.

{||+ The table's caption|-rowstylinggoeshere row code goes here|}

Row style

[edit]
Further information:§ Height, and§ Setting borders

Row style (height, width, borders, text alignment, background color, bolding, italics, etc.) may be added to a wikitable row by appendingCSS style properties to the row start line after the|- indicator.

Here is an example increasing the height of the middle row. The top row has italic text. The last row has bold text and a yellow background:

Wikitext

{|class=wikitable|-! Left!! Center!! Right|-style=font-style:italic;| Top left|| Top center|| Top right|-style=height:9em;id=mid| Middle left|| Middle center|| Middle right|-style="font-weight:bold; background-color:yellow;"| Bottom left|| Bottom center|| Bottom right|}

Produces

LeftCenterRight
Top leftTop centerTop right
Middle leftMiddle centerMiddle right
Bottom leftBottom centerBottom right

The row also contains anid attribute; this will be explained later in the section aboutlinking directly to a row.

Row headers

[edit]

With row headers you need to use a separate row in the wikitext for the row header cell. Here below is what a table looks like if the data cell wikitext is on the same line as the row header wikitext. The data cell text is bolded, and the data cell backgrounds are the same shade of gray as the column and row headers.

Wikitext

{|class=wikitable|+ The table's caption! Column 1!!Column 2!!Column 3|-! Row header 1|| Cell 2|| Cell 3|-! Row header A|| Cell B|| Cell C|}

Produces

The table's caption
Column 1Column 2Column 3
Row header 1Cell 2Cell 3
Row header ACell BCell C

Here is the table with aseparate wikitext row for each row header cell. The data cells have plain unbolded text, and a lighter background.

Wikitext

{|class=wikitable|+ The table's caption! Column 1!!Column 2!!Column 3|-! Row header 1| Cell 2|| Cell 3|-! Row header A| Cell B|| Cell C|}

Produces

The table's caption
Column 1Column 2Column 3
Row header 1Cell 2Cell 3
Row header ACell BCell C

Row numbers

[edit]

Table rows may be numbered with the assistance of templates provided for the purpose. SeeHelp:Sortable tables sections on row numbers, and these templates:

Link directly to a row

[edit]
Shortcuts

You can link directly to a row in a wikicode table, by including anid attribute on the line with the§ row start indicator whose value is theanchor for the link. For example, you could code:

|-

and then link to it usingThe [[#mid|middle row]] is the tallest one.which produces:

Themiddle row is the tallest one.    (Click to try it out!) 

Row template

[edit]
For adding a dynamic row number as a table column, see§ Row numbers.

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, may have much in common, e.g.:

  • the basic code for a table row
  • code for color, alignment, and sorting mode
  • fixed texts such as units
  • special formats for sorting

In such a case, it can be useful to create a template that produces the syntax for a table row, with the data as parameters. This can have many advantages:

  • easily changing the order of columns, or removing a column
  • easily adding a new column if many elements of the new column are left blank (if the column is inserted and the existing fields are unnamed, use a named parameter for the new field to avoid adding blank parameter values to many template calls)
  • computing fields from other fields, e.g. population density from population and area
  • duplicating content and providing span tags withdisplay: none; for the purpose of having one format forsorting and another for display
  • easy specification of a format for a whole column, such as color and alignment

Example:

Using{{Help:Table/example row template}}

Wikitext

{|class="wikitable sortable"|-!scope=col| a!scope=col| b!scope=col| a/b{{Help:Table/example row template|  50|200}}{{Help:Table/example row template|   8| 11}}{{Help:Table/example row template|1000| 81}}|}

Produces

aba/b
502000.25
8110.72727272727273
10008112.345679012346

Conditional table row

[edit]
Main page:Wikipedia:Conditional tables

For a conditional row in a table, we can have:

Wikitext

{|class=wikitable{{#if:1|{{!}}-  ! scope=row{{!}} row one, column one{{!}}row one, column two}}{{#if:|{{!}}-  ! scope=row{{!}} row two, column one{{!}}row two, column two}}|-  ! scope=row {{!}} row three, column one  | row three, column two|}

Produces

row one, column onerow one, column two
row three, column onerow three, column two

With comments to explain how it works, where note how the second row is missing:

Wikitext

{|class=wikitable<!--  Row one is shown because the '1' evaluates  to TRUE. -->{{#if:1|{{!}}-  ! scope=row{{!}} row one, column one<!--   Any {{!}}'s are evaluated to the pipe   character '|' since the template '!' just   contains '|'.  -->{{!}}row one, column two}}<!--  Row two is NOT shown because the space  between the ':' and the '|' evaluates to FALSE. -->{{#if:|{{!}}-  ! scope=row{{!}} row two, column one{{!}}row two, column two}}<!--  Row three is shown. -->|-  ! scope=row {{!}} row three, column one  | row three, column two|}

Produces

row one, column onerow one, column two
row three, column onerow three, column two

Cell operations

[edit]

Setting cell parameters

[edit]

At the start of a cell, add your parameter followed by a single pipe. For example,style="width: 300px;"| sets that cell to a width of 300 pixels. To set more than one parameter, leave a space between each one.

Wikitext

{|style="color: white;"|-|style="background-color: red;"|cell1|style="width: 300px; background: blue;"|cell2|style="background-color: green;"|cell3|}

Produces

cell1cell2cell3

Vertical alignment in cells

[edit]
See also:Help:Table/Advanced § Horizontal alignment in cells

Note: Thevalign=... attribute isdeprecated and MediaWiki may stop using it. See:Help:HTML in wikitext#Tables.
Note: Use{{Vertical align rows}} to align all rows at once.

By default, text is aligned to the vertical middle of the cell (2nd column in table below).CSS can be used to vertically align individual cells, or single rows.

Demo of vertical alignment of individual cells
Three
lines
of text
No alignmentTop-alignedMiddle-alignedBottom-aligned

Relevant wikitext:

|style=vertical-align:top |Top-aligned|style=vertical-align:middle |Middle-aligned|style=vertical-align:bottom |Bottom-aligned

The example below illustrates the need for top alignment of a row.

Row headerA longer piece of text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Imagine someone scrolling down the page, seeing the tops of "empty" columns, and wondering why they're empty.

Short text

To align the text to the top of each cell in the row, apply thestyle="vertical-align: top;" CSS to the row.

Wikitext

{|class=wikitablestyle=width:400px|-style=vertical-align:top!scope=rowstyle=width:10%| Row header|style=width:70%|A longer piece ...|style=width:20%|Short text|}

Produces

Row headerA longer piece of text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Imagine someone scrolling down the page, seeing the tops of "empty" columns, and wondering why they're empty.

Short text

Documentation and more options for the CSSvertical-align property ishere.

Cell content indenting and padding

[edit]

The contents of a cell can be indented or padded on any side. Also, the text can be aligned. In the third row the text is aligned to the right. See the following examples.

Wikitext

{|class=wikitable|-| Cell content that is not indented or padded|-|style="padding-left: 2em;"|<code>style="padding-left: 2em;"</code>|-|style="text-align:right; padding-right: 2em;"|<code>style="text-align:right; padding-right: 2em;"</code>|-|style="padding-top: 2em;"|<code>style="padding-top: 2em;"</code>|-|style="padding-bottom: 2em;"|<code>style="padding-bottom: 2em;"</code>|-|style="padding: 3em 5%;"|<code>style="padding: 3em 5%;"</code>{{space|4}} (Top and Bottom: 3em. Left and Right: 5%)|-|style="padding: 3em 4em 5%;"|<code>style="padding: 3em 4em 5%;"</code>{{space|4}} (Top: 3em. Left and Right: 4em. Bottom: 5%)|-|style="padding: 3%;"|<code>style="padding: 3%;"</code>{{space|4}} (Top, Right, Bottom, and Left: all 3%)|-|style="padding: 1em 20px 8% 9em;"|<code>style="padding: 1em 20px 8% 9em;"</code>{{space|4}} (Top: 1em. Right: 20px. Bottom: 8%. and Left: 9em.)|}

Produces

Cell content that is not indented or padded
style="padding-left: 2em;"
style="text-align:right; padding-right: 2em;"
style="padding-top: 2em;"
style="padding-bottom: 2em;"
style="padding: 3em 5%;"     (Top and Bottom: 3em. Left and Right: 5%)
style="padding: 3em 4em 5%;"     (Top: 3em. Left and Right: 4em. Bottom: 5%)
style="padding: 3%;"     (Top, Right, Bottom, and Left: all 3%)
style="padding: 1em 20px 8% 9em;"     (Top: 1em. Right: 20px. Bottom: 8%. and Left: 9em.)

Pattern for arguments:The arguments tostyle="padding: " can be seen as being ordered by a12-hour clock, starting atnoon and goingclockwise, in the following sense: "top" is associated with noon (i.e. 12 o'clock, the top of aclock), "right" is 3 o'clock, "bottom" is 6 o'clock, and "left" is 9 o'clock. The arguments are ordered clockwise starting at noon: top → right → bottom → left (see this[note 3] footnote for an example with an explanation).

This same order is also used elsewhere, such as when specifying§ cell borders withborder-style:.

Setting default cell padding

Usecellpadding= to set the default padding for each cell in a table. Ifclass=wikitable is used thencellpadding is ignored. The default space between cells can be changed usingcellspacing=.

Ifcellpadding is not used

Wikitext

{|style="border:1px solid black"|-| Cell|| Cell|-| Cell|| Cell|}

Produces

CellCell
CellCell

Usingcellpadding=10:

Wikitext

{|cellpadding=10;style="border:1px solid black"|-| Cell|| Cell|-| Cell|| Cell|}

Produces

CellCell
CellCell

Usingcellpadding=0:

Wikitext

{|cellpadding=0;style="border:1px solid black"|-| Cell|| Cell|-| Cell|| Cell|}

Produces

CellCell
CellCell

Usingcellpadding=0 andcellspacing=0:

Wikitext

{|cellpadding=0;cellspacing=0;style="border:1px solid black"|-| Cell|| Cell|-| Cell|| Cell|}

Produces

CellCell
CellCell

Individual cell borders

[edit]

The same§ CSS used for tables can be used in a cell's format specifier (enclosed in|...|) to put a border around each cell:

Wikitext

{|style="border-spacing: 2px; border: 1px solid darkgray;"!style="width: 140px;"| Left!style="width: 150px;"| Center!style="width: 130px;"| Right|-style="text-align: center;"|style="border: 1px solid blue;"|[[File:Starred.svg|120px]]|style="border: 1px solid #777777;"|[[File:Star full.svg|120px]]|style="border: 1px solid #22AA55;"|<!-- greenish border -->[[File:Stargreen.svg|120px]]|-style="text-align: center;"|Red star|| Orange star|| Green star|}

Produces

LeftCenterRight

Red starOrange starGreen star

Only the image cells have individual borders, not the text. The lower hex-colors (such as:#616161) are closer to black. Typically, all borders in a table would be one specific color.

Border styles

Thestyle='border:' andstyle='border-style:' properties can accept the following arguments:

ArgumentCell borderAdditional notes
nonestyle="border-style: none;"
solidstyle="border-style: solid;"
doublestyle="border-style: double;"
dashedstyle="border-style: dashed;"
dottedstyle="border-style: dotted;"
ridgestyle="border:5px ridge red;"3D ridged border
groovestyle="border:5px groove blue;"3D grooved border
insetstyle="border: 5px inset yellow;"3D inset border
outsetstyle="border: 5px outset cyan;"3D outset border
inheritstyle="border-style: inherit;"Inherit value from parent
initialstyle="border-style: initial;"Set to default value
Borders of a cell usingborder-top,border-right,border-bottom,border-left

Wikitext

{|!style="border-top: solid;"| <code>style="border-top: solid;"</code>|-|style="border-top: solid 2px red; border-right: dashed 3px green; border-bottom: double 5px blue; border-left: dotted 6px yellow;"|<pre>border-top: solid 2px red;border-right: dashed 3px green;border-bottom: double 5px blue;border-left: dotted 6px yellow;</pre>|}

Produces

style="border-top: solid;"
border-top: solid 2px red;border-right: dashed 3px green;border-bottom: double 5px blue;border-left: dotted 6px yellow;
Top, right, bottom, and left borders of a cell usingstyle='border-style:'

To set the left, right, bottom, or top border of a single cell, one may usestyle='border-style:' which takes between 1 and 4 arguments, each of which is eithernone,solid,double,dotted,dashed,groove,ridge,inset,outset,inherit, orinitial.

These arguments are ordered according to the§ pattern described here.For instance,style="border-style: solid none solid none;" where the four parameters correspond respectively to the
     'border-style: top right bottom left;'
borders of the cell.For reasons described after this example, there are many ways to change the followingcode that wouldnot result in any changes to the table that is actuallydisplayed.

Wikitext

{|class=wikitable|-| Top_Left<!-- border-style: top right bottom left; -->|style="border-style: solid solid none none;"| Top_Center| Top_Right|-|style="border-style: none none solid solid;"| Middle_Left|style="border-style: none none none none;"| Middle_Center|style="border-style: solid solid none none;"| Middle_Right|-| Bottom_Left|style="border-style: none none solid solid;"| Bottom_Center| Bottom_Right|}

Produces

Top_LeftTop_CenterTop_Right
Middle_LeftMiddle_CenterMiddle_Right
Bottom_LeftBottom_CenterBottom_Right

Note, however, that in the following table, none of the central cell's (i.e.Middle_Center's) borders are removed despite the codestyle="border-style: none none none none;":

Wikitext

{|class=wikitable|-| Top_Left|| Top_Center|| Top_Right|-| Middle_Left|style="border-style: none none none none;"| Middle_Center| Middle_Right|-| Bottom_Left|| Bottom_Center|| Bottom_Right|}

Produces

Top_LeftTop_CenterTop_Right
Middle_LeftMiddle_CenterMiddle_Right
Bottom_LeftBottom_CenterBottom_Right

This happens because the codeclass="wikitable" places a border (top, right, bottom, and left) aroundevery cell in the table so that, for instance, there are actuallytwo borders between the cells "Middle_Center" and "Middle_Right".So to remove the border between cells "Middle_Center" and "Middle_Right", it is necessary to remove both the right border of "Middle_Center"and the left border of "Middle_Right":

Wikitext

{|class=wikitable|-| Top_Left|| Top_Center|| Top_Right|-| Middle_Left<!-- 'border-style: top right bottom left;' -->|style="border-style: none none none none;"| Middle_Center|style="border-style: none none none none;"| Middle_Right<!-- In the above line, the three left-most "none" arguments can be replaced with "solid" (or other valid arguments) and there would be no change to the table that is displayed. Only the fourth argument, which is Middle_Right's left border, needs to be "none". For example, the line above could be replaced with:| | Middle_Right-->|-| Bottom_Left|| Bottom_Center|| Bottom_Right|}

Produces

Top_LeftTop_CenterTop_Right
Middle_LeftMiddle_CenterMiddle_Right
Bottom_LeftBottom_CenterBottom_Right

To remove selected external borders of a wikitable, both remove them from the adjacent cells and begin the whole table with code like{|.

Replacing{| with
     {|
has the effect of removing all cell borders that would otherwise appear by default around every cell in the table.With this change, you mustinsert asingle cell border between two adjacent cells rather than removetwo cell borders.

Table cell templates

[edit]
See also:Template:Shade

See{{Table cell templates}} for a large set of templates to configure text and color in cells in a standard way, producing stock output. For example: "Yes" ({{Yes}}), "No" ({{No}}), "—" ({{N/A}}), "N/A" ({{N/A|N/A}}), "?" ({{dunno}}), on colored backgrounds.

Template output for selected table cell templates
Template usageUsing templateWithout template
{{Yes}}YesYes
{{No}}NoNo
{{Dunno}}??
{{N/A}}
{{N/A|N/A}}N/AN/A
{{n/a|n/a}}n/an/a

For example, seeComparison of text editors, which makes frequent use of table cell templates.

Tooltips

[edit]

You can add tooltips to columns by using the{{Tooltip}} template. Simply replace the column-title with{{Tooltip|Column title|The tool tip}}, which makes it appear like so:Column title. Use{{abbr}} (same format) for abbreviations. For example:Pop.

Workarounds

[edit]

Scrolling tables

[edit]

SeeHelp:Table/Advanced § Scrolling tables and the following sections for scrolling, sticky headers, and combinations thereof.

Overflowing tables

[edit]
Note:Template:Sticky table start does the same thing, and also shortens the table vertically too via a verticalscrollbar. Such a scroll box is a problem though if the sticky headers are too large. In some cases, only a horizontal scrollbar (as below) may be desired. In that caseTemplate:Sticky header may be preferred as long as the top sticky header is not too tall. The overflow code below can not be used with it, or sticky will not work.{{Sticky header}} scrolling is via the whole page, not just for the table.

A horizontal scrollbar for the whole page shows up for any wikitable that is too wide for the screen. To create a scrollbar just for the table the following code may be used. Place the following code above a wikitable initialization:

<divclass="overflowbugx"style="overflow-x:auto;">

Then, after the closing bracket for the wikitable, place the following code:

</div>

This will prevent the table from causing the entire page to scroll when scrolling through the table horizontally.

For more info see:Template:Sticky header#Known issues.

Non-rectangular tables

[edit]

{{diagonal split header|HEADER-FOR-ROW-HEADERS|HEADER-FOR-COLUMN-HEADERS}} can be used to diagonally split a header cell, as in the top-left cell in the rendered result below:[note 4]

Wikitext

{|class=wikitable! {{diagonal split header|From|To}}! Solid!! Liquid!! Gas|-! Solid| Solid-solid transformation|| Melting|| Sublimation|-! Liquid| Freezing||{{sdash}}|| Boiling/evaporation|-! Gas| Deposition|| Condensation||{{sdash}}|}

Produces

To
From
SolidLiquidGas
SolidSolid-solid transformationMeltingSublimation
LiquidFreezingBoiling/evaporation
GasDepositionCondensation

Cell borders can be hidden by addingborder: none; background: none; to the style attributes of either the table or the cell,[note 5] though this may not work in older browsers. Another use case for this is for implementing aligned multi-column tables:

Wikitext

{|class=wikitablestyle="border: none; background: none;"!colspan=2rowspan=2style="border: none; background: none;"| [[File:Pfeil_SO.svg |none|link=|20px]]!colspan=3| To|-! Solid!! Liquid!! Gas|-!rowspan=3| From! Solid| Solid–solid transformation|| Melting|| Sublimation|-! Liquid| Freezing||{{sdash}}|| Boiling/evaporation|-! Gas| Deposition|| Condensation||{{sdash}}|}

Produces

To
SolidLiquidGas
FromSolidSolid–solid transformationMeltingSublimation
LiquidFreezingBoiling/evaporation
GasDepositionCondensation

The removal of the link on an image isdependent on it being purely decorative (as it will be ignored by assistive devices).

Wikitext

{|class=wikitablestyle="border: none; background: none;"!scope=col| Year!scope=col| Size|rowspan=5style="border: none; background: none;"|!scope=col| Year!scope=col| Size|rowspan=5style="border: none; background: none;"|!scope=col| Year!scope=col| Size|-| 1990|| 1000<br>(est)|| 2000|| 1357|| 2010|| 1776|-| 1991|| 1010|| 2001|| 1471|| 2011|| 1888|-|colspan=2style="text-align: center;"||colspan=2style="text-align: center;"||colspan=2style="text-align: center;"||-| 1999|| 1234|| 2009|| 1616|| 2019|| 1997<br>(est)|}

Produces

YearSizeYearSizeYearSize
19901000
(est)
2000135720101776
199110102001147120111888
199912342009161620191997
(est)

Rendering the pipe

[edit]

When cellcontent that contains apipe character does not render correctly, simply add an empty format for that cell. The second pipe character in a line of|cell code will not display; it is reserved for adding a format. Wikicode between the first and second pipe is a format, but since emptiness or an error there is ignored, it just disappears. When this happens, add a dummy format.(For a real format, see§ HTML attributes.) Use a third pipe character to render your first pipe character.

Rendering the first pipe when it is the third pipe in the cell code.

Wikitext

{|class=wikitable|-|''formatting''|P|i|p|e||C|e|l|l|2||-|''formatting''|P|i|p|e||''formatting''|C|e|l|l|2||-||P|i|p|e|s||C|e|l|l|2||}

Produces

P|i|p|e|e|l|l|2|
P|i|p|eC|e|l|l|2|
P|i|p|e|se|l|l|2|

The third and later pipe characters will render, but to display twoadjacent pipe characters in a cell, (instead of having them act as the first pipe at the start of a new cell), other pipe-rendering options are needed. Instead of using a dummy format to render a pipe, you can render it directly by 1)<nowiki>|</nowiki> (preferred) or 2) html:&#124; or&#x7C;. Each line of cell code in the following table has one wikicode pipe.

Displaying adjacent pipes

Wikitext

{|class=wikitable|-|<nowiki>|</nowiki> Pipes34:<nowiki>||</nowiki>|-|&#124; Pipes34:&#124;&#x7C;|}

Produces

| Pipes34:||
| Pipes34:||

Template{{!}}, because of the order in which things are parsed, is equivalent to typing in a single | pipe character. The single<nowiki />| parser-tag does not apply here. See how they do notescape the second pipe, as &#124 and<nowiki>|</nowiki> did above:

Common mechanisms that do not work in tables.

Wikitext

{|class=wikitable|-|<nowiki/>| Pipe3:||-|Pipe2:{{!}} Pipe3:{{!}}|}

Produces

Pipe3:|
Pipe3:|

Classes

[edit]
See also:Help:User style andHelp:CSS

There are several otherCSS classes, besides the basicclass=wikitable, documented§ above.

In the first line of table code, after the{|, instead of specifying a style directly, you can also specify a CSS class, which may be used to apply styles. The style for this class can be specified in various ways:

  • in the software itself, per skin (for example the class§ sortable)
  • collectively for all users of one wiki inMediaWiki:Common.css (for example, on this and some other projects there is or was the class wikitable, later moved toshared.css)
  • separately per skin inMediaWiki: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 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:

Wikitext

{|style="border-spacing: 2px;"|+ Multiplication table|-!scope=col| &times;!scope=col| 1!scope=col| 2!scope=col| 3|-!scope=row| 1| 1|| 2|| 3|-!scope=row| 2| 2|| 4|| 6|}

Produces

Multiplication table
×123
1123
2246

becomes this:

Wikitext

{|class=wikitable|+ Multiplication table|-!scope=col| &times;!scope=col| 1!scope=col| 2!scope=col| 3|-!scope=row| 1| 1|| 2|| 3|-!scope=row| 2| 2|| 4|| 6|}

Produces

Multiplication table
×123
1123
2246

simply by replacing inline CSS for the table byclass=wikitable. This is because thewikitable class inMediaWiki:Common.css contains a number oftable.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:

Wikitext

{|class=wikitablestyle="font-style: italic; font-size: 120%; border: 3px dashed red;"|+ Multiplication table|-!scope=col| &times;!scope=col| 1!scope=col| 2!scope=col| 3|-!scope=row| 1| 1|| 2|| 3|-!scope=row| 2| 2|| 4|| 6|}

Produces

Multiplication table
×123
1123
2246

Notice that the table retains the gray background of thewikitable class, and the headers are still bold and centered. But now the text formatting has been overridden by the localstyle= 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.

Indenting tables

[edit]

While tables should not normally be indented, when their surrounding paragraphs are also indented, you can indent tables usingmargin-left.

To achieve the same indentation as a colon, usemargin-left:1.6em.

Wikitext

{|class="wikitable"style="margin-left:1.6em;"|-! Header 1! Header 2|-| row 1, cell 1| row 1, cell 2|-| row 2, cell 1| row 2, cell 2|}

Produces

Header 1Header 2
row 1, cell 1row 1, cell 2
row 2, cell 1row 2, cell 2

Tables on talk pages

[edit]
Note: Concerning colons on talk pages, see commentshere from a blind editor (Graham87) who uses ascreen reader. Scroll down to the table comments. It also verifies the previous section above.

Indentation applied to only thefirst line of the table wiki text, (the line that begins with "{|") is sufficient to indent the entire table.

:::{| class=wikitable

Do not attempt to use colons for indentation anywhere within the rest of the table code (not even at the beginning of a line), as that will prevent the MediaWiki software from correctly reading the code for the table.

Public domain image tables

[edit]

It may be difficult or time-consuming to convert a table on the web to a wikitable. Especially if it can't be copied and pasted into the visual editor or a spreadsheet. Even more time-consuming if it is both difficult and regularly updated.

SeeCommons:Template:PD-chart. All image tables and charts are in the public domain unless they contain copyrightable things such as photos, etc.. Those can be removed.

So if necessary, take a screenshot, crop out the table with any image editor, andupload it to theWikimedia Commons. Add {{PD-chart}} to it.

See also

[edit]
Note: Seetop of page for more links to table help pages.

Templates

[edit]

Some commonly used table templates usingTemplateStyles:

Notes

[edit]
  1. ^Collapsible tables: the classcollapsible prevents editing collapsed tables using theVisual editor; usemw-collapsible instead. Seehere for further details.
  2. ^border: none; to avoid an empty column in tables narrower than the browser window in Android Chrome.
  3. ^Instyle="padding: 3em 4em 5%;", the value4em is used for both the "left" padding and the "right" padding, so the order going clockwise is: top (3em) → right [and hence also left] (4em) → bottom (5%); there is no "→ left" in this case because the "left" padding has already been defined. Instyle="padding: 3em 5%;", the value3em is used for both the "top" and "bottom" padding while the value5% is used for both the "left" and "right" padding, so the order going clockwise is: top [and hence also bottom] (3em) → right [and hence also left] (5%); there is no "→ bottom" nor is there "→ left" in this case because the "bottom" and "left" padding have already been defined. The same reasoning also applies tostyle="padding: 1em 20px 8% 9em;", andstyle="padding: 3%;".
  4. ^A simplified version ofTemplate:Table_of_phase_transitions
  5. ^Applyingbackground: none to the entire table will, perhaps predictably, subtly alter its color palette.

External links

[edit]

Wikimedia sister projects

[edit]
Source editor
VisualEditor
About Wikipedia (?)
Help for readers (?)
Contributing
to Wikipedia
 (?)
Getting started (?)
Dos and don'ts (?)
How-to pages and
information pages (?)
Coding (?)
Directories (?)
General
technical help
Special
page
-related
Wikitext
Links anddiffs
Media files: images,
videos and sounds
Other graphics
Templates and
Lua modules
Data structure
HTML andCSS
Customisation
and tools
Automated editing
Retrieved from "https://en.wikipedia.org/w/index.php?title=Help:Table&oldid=1318015125"
Categories:

[8]ページ先頭

©2009-2025 Movatter.jp