Help:Tables/pt
Nota: Quando modificais esta página, estais a aceitar que a vossa contribuição se publique no marco de CC0. Olhem Páginas de ajuda de domínio público para mais informação. |
- Para conhecer a estrutura das tabelas da base de dados do MediaWiki, consulte Manual:Disposição da Base de Dados
Pode criar tabelas nas páginas da wiki. Regra geral, é melhor evitar usar tabelas a menos que sejam mesmo necessárias. Normalmente, os códigos de formatação de tabelas tornam a edição de páginas mais complexa.[1]
Resumo dos elementos wiki de construção de tabelas
{| | início da tabela, obrigatório |
|+ | título da tabela, opcional; só pode ser colocado entre o início da tabela e a primeira linha da tabela |
|- | linha da tabela, opcional na primeira linha — a wiki assume a primeira linha mesmo sem este elemento. |
! | célula de cabeçalho de tabela, opcional. Células consecutivas de cabeçalho de tabela podem ser colocadas numa só linha, separadas por dois pontos de exclamação (!! ), ou uma por linha, com cada linha começada por um ponto de exclamação (! ).
|
| | célula de dados da tabela, opcional. Células consecutivas de dados de tabela podem ser colocadas numa só linha, separadas por duas barras verticais (|| ), ou uma por linha, com cada linha começada por uma barra vertical (| ).
|
|} | fim da tabela, obrigatório |
- Os elementos de criação de tabelas têm de começar numa linha nova, exceto os sinais duplos (
||
) e (!!
) para adicionar elementos consecutivos numa só linha. No entanto, espaços em branco no início da linha são ignorados. - Atributos XHTML. Cada elemento, exceto o fim da tabela, aceita opcionalmente um ou mais atributos XHTML. Os atributos têm de estar na mesma linha que o elemento. Separe os atributos entre si com um só espaço.
- As células e títulos (
|
ou||
,!
ou!!
, e|+
) têm conteúdo. Por isso, separe os atributos do conteúdo usando uma só barra vertical (|
). O conteúdo da célula pode ser colocado na mesma linha ou nas linhas seguintes. - Os elementos da tabela e das linhas (
{|
e|-
) não têm conteúdo. Não coloque a barra vertical (|
) após os atributos opcionais. Se colocar, por erro, uma barra vertical a seguir aos atributos de um elemento de tabela ou de linha, o analisador sintático apaga a barra vertical e o último atributo se este estiver encostado à barra vertical!
- As células e títulos (
- O conteúdo pode ser colocado: (a) a seguir ao elemento de célula, na mesma linha, após qualquer atributo XHTML opcional, ou (b) nas linhas abaixo do elemento de célula.
Content that uses wiki markup that itself needs to start on a new line, such as lists, headings, or nested tables, must be on its own new line.
- Pipe character as content.
* Para utilizar a barra vertical (|
) no conteúdo de uma célula, como é feito acima, use o elemento wiki <nowiki>|</nowiki>
.
Exemplos
Create a table with editor toolbar
In wikitext editor, place the caret where you want to insert a table. Then, in the toolbar, press “Edição avançada”, then choose Tabela button. A dialog opens.
From the dialog, you can choose whether to enable a table header row, to stylize the table with border and to make the table sortable. A preview example is displayed. You can also set row and column counts you need. Then, press “Inserir” button.
By default, the following code is generated:
Wikicode:
{| class="wikitable" style="margin:auto" |+ Texto da legenda |- ! Texto do cabeçalho !! Texto do cabeçalho !! Texto do cabeçalho |- | Exemplo || Exemplo || Exemplo |- | Exemplo || Exemplo || Exemplo |- | Exemplo || Exemplo || Exemplo |}
Result:
Texto do cabeçalho | Texto do cabeçalho | Texto do cabeçalho |
---|---|---|
Exemplo | Exemplo | Exemplo |
Exemplo | Exemplo | Exemplo |
Exemplo | Exemplo | Exemplo |
Minimal syntax
Os seguintes exemplos começam pelos conceitos básicos e de forma progressiva complementam-nos, explorando mais possibilidades de construção e formatação de tabelas.
You type | You get | ||||||
---|---|---|---|---|---|---|---|
{| |Orange |Apple |- |Bread |Pie |- |Butter |Ice cream |} |
|
The cells in the same row can be listed on one line separated by ||
(two pipe symbols).
If the text in the cell should contain a line break, use <br />
instead.
You type | You get | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| |Orange||Apple||more |- |Bread||Pie||more |- |Butter||Ice<br/>cream||and<br/>more |} |
|
Extra spaces within cells in the wiki markup, as in the wiki markup below, do not affect the actual table rendering.
You type | You get | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| | Orange || Apple || more |- | Bread || Pie || more |- | Butter || Ice cream || and more |} |
|
You can have longer text or more complex wiki syntax inside table cells, too:
You type | You get | ||
---|---|---|---|
{| |Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | * Lorem ipsum dolor sit amet * consetetur sadipscing elitr * sed diam nonumy eirmod tempor invidunt |} |
|
Table headers
Table headers can be created by using "!
" (exclamation mark) instead of "|
" (pipe symbol).
Headers usually show up bold and centered by default.
You type | You get | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{| ! style="text-align:left;"| Item ! Amount ! Cost |- |Orange |10 |7.00 |- |Bread |4 |3.00 |- |Butter |1 |5.00 |- !Total | |15.00 |} |
|
Caption
A table caption can be added to the top of any table as follows.
You type | You get | ||||||
---|---|---|---|---|---|---|---|
{| |+Food complements |- |Orange |Apple |- |Bread |Pie |- |Butter |Ice cream |} |
|
class="wikitable"
Basic styling (light gray background, borders, padding and align left) can be achieved by adding class="wikitable".
You type | You get | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable" |+Food complements |- |Orange |Apple |- |Bread |Pie |- |Butter |Ice cream |} |
|
HTML colspan and rowspan
You can use HTML colspan and rowspan attributes on cells for advanced layout.
You type | You get | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" !colspan="6"|Shopping List |- |rowspan="2"|Bread & Butter |Pie |Buns |Danish |colspan="2"|Croissant |- |Cheese |colspan="2"|Ice cream |Butter |Yogurt |} |
|
Note about large tables (noresize class)
The use of the wrapping div.noresize will ensure your table is optimized for mobile and is extremely important for large tables e.g. tables with more than 4 columns or large columns. Failure to use this element will cause your content to overlap UI elements e.g. the Vector 2022 sidebar or to break mobile display. This will cause the table to have a horizontal scroll bar when the table is too big for the content.
Shopping List | |||||
---|---|---|---|---|---|
Areallyreallyreallyreallylongstringwillcauseyourtableto | Pie | Buns | Danish | Croissantsmaycausetexttoincreasethesizeofyourcolumnsoitbreaksoutofthecontent area if you do not wrap the table with noresize. | |
Cheese | Ice cream | Butter | Yogurt |
HTML attributes
You can add HTML attributes to tables. For the authoritative source on HTML attributes, see the W3C's HTML Specification page on tables.
Attributes on tables
Placing attributes after the table start tag ({|
) applies attributes to the entire table.
You type | You get | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" style="text-align: center; color: green;" |Orange |Apple |12,333.00 |- |Bread |Pie |500.00 |- |Butter |Ice cream |1.00 |} |
|
Attributes on cells
You can put attributes on individual cells. For example, numbers may look better aligned right.
You type | You get | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" | Orange | Apple | style="text-align:right;" | 12,333.00 |- | Bread | Pie | style="text-align:right;" | 500.00 |- | Butter | Ice cream | style="text-align:right;" | 1.00 |} |
|
You can also use cell attributes when you are listing multiple cells on a single line.
Note that the cells are separated by ||
, and within each cell the attribute(s) and value are separated by |
.
You type | You get | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" | Orange || Apple || style="text-align:right;" | 12,333.00 |- | Bread || Pie || style="text-align:right;" | 500.00 |- | Butter || Ice cream || style="text-align:right;" | 1.00 |} |
|
Attributes on rows
You can put attributes on individual rows, too.
You type | You get | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" | Orange | Apple | style="text-align:right;"| 12,333.00 |- | Bread | Pie | style="text-align:right;"| 500.00 |- style="font-style: italic; color: green;" | Butter | Ice cream | style="text-align:right;"| 1.00 |} |
|
Attributes on caption and headers
Attributes can be added to the caption and headers as follows.
You type | You get | ||||||||
---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" |+ style="caption-side:bottom; color:#e76700;"|''Food complements'' |- ! style="color:green" | Fruits ! style="color:red" | Fats |- |Orange |Butter |- |Pear |Pie |- |Apple |Ice cream |} |
|
Border width
If "border-width:" has only one number, it is for all four border sides:
You type | You get | |
---|---|---|
{|style="border-style: solid; border-width: 20px" | Hello |} |
|
If "border-width:" has more than one number, the four numbers are for top, right, bottom, left (REMEMBER clockwise order ↑→↓←):
You type | You get | |
---|---|---|
{|style="border-style: solid; border-width: 10px 20px 100px 0" | Hello |} |
|
- When there are fewer than 4 values :
- three values i.e.
top
,right
,bottom
: then the default value forleft
is the one ofright
(second value). Width is then the same on left and right side. - two values i.e.
top
,right
: then the default value forbottom
is the one oftop
(first value), andleft
by default is assigned the value ofright
(second value). Width on top is then the same as on bottom; width on left is the same as on right. - one value i.e.
top
: then the default value forright
is the one oftop
and it is the same forbottom
andleft
. The fourth width are the same and build a regular border. This is a writing shortcut.
- three values i.e.
Another method to define the widths of the four sides of a cell is to use "border-left", "border-right", "border-top" and "border-bottom":
You type | You get | |
---|---|---|
{|style="border-left:solid 10px black;border-right:solid 20px black;border-top:solid 30px black;border-bottom:solid 40px black;" align="center" | Hello |} |
|
The HTML attributes (such as "width=", "border=", "cellspacing=", "cellpadding=") do not need any length unit (the pixel unit is assumed). They are also invalid in HTML 5.
"Cellpadding" is for setting the space between the cell wall and the cell content.
The CSS style properties (which override the HTML attributes) require an explicit length unit (if the value is not 0) such as "px" for the pixel.
With HTML attributes and CSS styles
CSS style attributes can be added with or without other HTML attributes.
You type | You get | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable" style="color:green; background-color:#ffffcc;" cellpadding="10" |Orange |Apple |- |Bread |Pie |- |Butter |Ice cream |} |
|
Padding
It represents the internal margin between the contents and the border of the cell.
You type | You get | |||
---|---|---|---|---|
{|class=wikitable | style="padding: 10px" | Example of style="padding:10px" |- | style="padding: 50px" | Example of style="padding:50px"<br/><br/>Specify the padding on '''EACH CELL''' |- | style="padding:100px" | Example of style="padding:100px" |} |
|
Column width
Column width can be added as follows.
You type:
{| class="wikitable" style="width: 85%;" | colspan="2" | This column width is 85% of the screen width |- | style="width: 30%"| '''This column is 30% counted from 85% of the screen width''' | style="width: 70%"| '''This column is 70% counted from 85% of the screen width''' |}
You get:
This column width is 85% of the screen width | |
This column is 30% counted from 85% of the screen width | This column is 70% counted from 85% of the screen width |
Accessibility of table header cells
Table header cells do not explicitly specify which table data cells they apply to (those on their right on the same row, or those below them on the same column). When the table is rendered in a visual 2D environment, this is usually easy to infer.
However when tables are rendered on non-visual media, you can help the browser to determine which table header cell applies to the description of any selected cell (in order to repeat its content in some accessibility helper) using a scope="row" or scope="col" attribute on table header cells. In most cases with simple tables, you'll use scope="col" on all header cells of the first row, and scope="row" on the first cell of the following rows:
You type | You get | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" |- ! scope="col"| Item ! scope="col"| Quantity ! scope="col"| Preço |- ! scope="row"| Bread | 0.3 kg | $0.65 |- ! scope="row"| Butter | 0.125 kg | $1.25 |- ! scope="row" colspan="2"| Total | $1.90 |} |
|
Alignment
Table alignment
Table alignment is achieved by using CSS. The table alignment is controlled by margins. A fixed margin on one side will make the table to be aligned to that side, if on the opposite side the margin is defined as auto. To have a table center aligned, you should set both margins to auto
For example, a right-aligned table:
You type | You get | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable" style="margin-left: auto; margin-right: 0px;" | Orange | Apple |- | Bread | Pie |- | Butter | Ice cream |} Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. |
And a center-aligned table:
You type | You get | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable" style="margin: auto;" | Orange | Apple |- | Bread | Pie |- | Butter | Ice cream |} Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. |
Table floating around text
If you align a table to the right or the left side of the page, the text that comes after the table starts at the end of it, leaving an empty space around the table.
You can make the text to be wrapped around the table by making the table to float around the text instead of just aligning it.
This can be achieved using the float
CSS attribute, which can specify where the table floats to the right side or to the left.
When using float, margins doesn't control table alignment and can be used to specify the margin between the table and the surrounding text.
You type | You get | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable" style="float:right; margin-left: 10px;" | Orange | Apple |- | Bread | Pie |- | Butter | Ice cream |} Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. |
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. |
Cell contents alignment
The alignment of cell contents can be controlled with 2 different CSS properties: text-align
and vertical-align
.
text-align
can be specified at the table, row or individual cells, while vertical-align
only can be specified at individual rows or cells.
You type | You get | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" |- style="vertical-align:top;" | style="height:100px; width:100px; text-align:left;" | A | style="height:100px; width:100px; text-align:center;" | B | style="height:100px; width:100px; text-align:right;" | C |- style="vertical-align:middle;" | style="height:100px; width:100px; text-align:left;" | D | style="height:100px; width:100px; text-align:center;" | E | style="height:100px; width:100px; text-align:right;" | F |- style="vertical-align:bottom;" | style="height:100px; width:100px; text-align:left;" | G | style="height:100px; width:100px; text-align:center;" | H | style="height:100px; width:100px; text-align:right;" | I |} |
|
Caveats
Negative numbers
If you start a cell on a new line with a negative number with a minus sign (or a parameter that evaluates to a negative number), your table can get broken, because the characters |-
will be parsed as 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
).
CSS vs attributes
Table borders specified through CSS rather than the border attribute will render incorrectly in a small subset of text browsers.
Common attributes for columns, column groups and row groups
The MediaWiki syntax for tables currently offers no support for specifying common attributes for columns (with the HTML element <col />
), column groups (HTML element <colgroup></colgroup>
) and row groups (HTML elements <thead></thead>
, <tbody></tbody>
and <tfoot></tfoot>
).
Those standard HTML elements are not accepted even in their HTML or XHTML syntax.
All the rows and cells (header or data) of the table are rendered within a single implicit row group (HTML element <tbody></tbody>
) without any attributes or styles.
Tables and the Visual Editor (VE)
- See also: Ajuda:Editor Visual/Guia do Utilizador
See Phab: T108245: "Fully support basic table editing in the visual editor".
See the list of tasks. Finished tasks are struck. It can be difficult to figure out from the technical language there what exactly has been improved, or what features have been added. Please add explanatory info below.
Can now move or delete columns and rows
Click on a column or row header. Then click on the arrow. From the popup menu click on "Move" or "Delete".
Insert blank row or column
From the same popup menu click on "Insert".
Copy table from web page to Visual Editor
It is possible to copy and paste a table from a web page directly into the Visual Editor (VE). To do so safely, use a sandbox and check the table for proper coding in wikitext source mode and proper display in the Visual Editor and in preview mode.
Helping tools
- Excel2Wiki allows you to copy a spreadsheet from Excel, Apache OpenOffice, LibreOffice, or Gnumeric to convert it into wikicode table.
See also
Notes
- ↑ Podem ser criadas tabelas nas páginas da wiki, quer usando diretamente os elementos XHTML de formatação de tabelas, quer usando os elementos de formatação wiki para defini-las. Os elementos de formatação de tabelas XHTML e o seu uso são amplamente descritos em vários sites na Internet e não serão discutidos aqui. A vantagem dos elementos de formatação wiki, é que a tabela é construída usando caracteres normais que, em comparação com os correspondentes elementos XHTML, tendem a facilitar a compreensão da estrutura da tabela ao editar a página.
- ↑ HTML table cellpadding Attribute