Ajuda: Tabelas
| 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. |
- "Tabelas" redireciona para aqui: para informação sobre estrutura da tabela da base de dados, consulte Manual: Disposição da Base de Dados.
Pode criar tabelas nas páginas da wiki. Como regra geral, é melhor evitar a utilização de uma tabela, a menos que precise de uma. A marcação de tabela geralmente complica a edição da página.[1]
Resumo da marcação de tabela da wiki
| {| | início da tabela, "obrigatório" |
| |+ | título da tabela, "opcional;" apenas entre o início da tabela e a linha da tabela |
| |- | linha da tabela, "opcional na primeira linha" — o mecanismo da wiki assume a primeira linha |
| ! | célula do cabeçalho da tabela, "opcional." Células consecutivas do cabeçalho da tabela podem ser adicionadas na mesma linha, separadas por dois pontos de exclamação (!!), ou começar nas novas linhas, cada uma com o seu ponto de exclamação (!).
|
| | | célula dos dados da tabela, "opcional". Células consecutivas dos dados da tabela podem ser colocadas a mesma linha, separadas por duas barras verticais (||), ou começar nas novas linhas, cada uma com a sua 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 HTML. Cada marca, exceto o fim da tabela, aceita opcionalmente um ou mais atributos HTML. Os atributos têm de estar na mesma linha que a marca. Separe os atributos entre si com um só espaço.
- As células e legenda (
|ou||,!ou!!, e|+) têm conteúdo. Por isso, separe os atributos do conteúdo utilizando 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 legenda (
- O conteúdo pode ser colocado: (a) a seguir à marca da célula na mesma linha depois de quaisquer atributos HTML opcionais, ou (b) nas linhas debaixo da marca da 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.
- Caráter da barra vertical como conteúdo. Para utilizar o caráter barra vertical (
|) numa tabela, utilize a escaping<nowiki>|</nowiki>.
- Caráter da barra vertical como conteúdo. Para utilizar o caráter barra vertical (
Básico
Criar uma tabela com a barra de ferramentas do editor
No editor do texto wiki, coloque o caráter onde quer inserir uma tabela.
Depois, na barra de ferramentas, clique em “Edição avançada”, e escolha o botão
Tabela.
É aberta uma janela.
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:
Código da wiki:
{| 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
|}
Resulatdo:
| Texto do cabeçalho | Texto do cabeçalho | Texto do cabeçalho |
|---|---|---|
| Exemplo | Exemplo | Exemplo |
| Exemplo | Exemplo | Exemplo |
| Exemplo | Exemplo | Exemplo |
Sintaxe mínima
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.
| Digita | Obtém | ||||||
|---|---|---|---|---|---|---|---|
{|
|Laranja
|Maçã
|-
|Pão
|Torta
|-
|Manteiga
|Gelado
|}
|
|
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.
| Digita | Obtém | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
{|
|Laranja||Maçã||mais
|-
|Pão||Torta||mais
|-
|Manteiga||Gelado<br>||e<br/>mais
|}
|
|
Extra spaces within cells in the wiki markup, as in the wiki markup below, do not affect the actual table rendering.
| Digita | Obtém | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
{|
| Laranja || Maçã || mais
|-
| Pão || Torta || mais
|-
| Manteiga || Gelado || e mais
|}
|
|
You can have longer text or more complex wiki syntax inside table cells, too:
| Digita | Obtém | ||
|---|---|---|---|
{|
|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
|}
|
|
Cabeçalhos da tabela
Table headers can be created by using "!" (exclamation mark) instead of "|" (pipe symbol).
Headers usually show up bold and centered by default.
| Digita | Obtém | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{|
! style="text-align:left;"| Item
! Quantidade
! Custo
|-
|Laranja
|10
|7.00
|-
|Pão
|4
|3.00
|-
|Manteiga
|1
|5.00
|-
!Total
|
|15.00
|}
|
|
Legenda
A table caption can be added to the top of any table as follows.
| Digita | Obtém | ||||||
|---|---|---|---|---|---|---|---|
{|
|+Complementos alimentares
|-
|Laranja
|Maçã
|-
|Pão
|Torta
|-
|Manteiga
|Gelado
|}
|
|
class="wikitable"
Basic styling (light gray background, borders, padding and align left) can be achieved by adding class="wikitable".
| Digita | Obtém | ||||||
|---|---|---|---|---|---|---|---|
{| class="wikitable"
|+Complementos alimentares
|-
|Laranja
|Maçã
|-
|Pão
|Torta
|-
|Manteiga
|Gelado
|}
|
|
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.
You type:
<div class="noresize">
{| class="wikitable"
! colspan="6" |Shopping List
|-
| rowspan="2" |Areallyreallyreallyreallylongstringwillcauseyourtableto
| Pie
| Buns
| Danish
| colspan="2" |Croissantsmaycausetexttoincreasethesizeofyourcolumnsoitbreaksoutofthecontent area if you do not wrap the table with noresize.
|-
| Cheese
| colspan="2" |Ice cream
| Butter
| Yogurt
|}
</div>
You get:
| 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 forleftis 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 forbottomis the one oftop(first value), andleftby 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 forrightis the one oftopand it is the same forbottomandleft. 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 whether the table floats to the right side or to the left.
When using float, margins don'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. |
Alinhamento dos conteúdos da célula
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.
| Digita | Obtém | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
{| 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
|}
|
|
Advertências
Números negativos
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. atributos
Table borders specified through CSS rather than the border attribute will render incorrectly in a small subset of text browsers.
Atributos comuns para colunas, grupos de colunas e grupos de linhas
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.
Tabelas e Editor Visual (VE)
- Consulte também: Ajuda: Editor Visual/Guia do Utilizador
Consulte 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.
Agora pode mover ou eliminar as colunas e linhas
Clique numa coluna ou cabeçalho da linha. Depois clique na seta. No menu da janela, clique em "Mover" ou "Eliminar".
Inserir uma linha ou coluna em branco
No mesmo menu da janela, clique em "Inserir".
Copiar a tabela da página da Web para o Editor Visual
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.
Ferramentas de ajuda =
- Excel2Wiki allows you to copy a spreadsheet from Excel, Apache OpenOffice, LibreOffice, or Gnumeric to convert it into wikicode table.
Consultar também
Notas
- ↑ Podem ser criadas tabelas utilizando diretamente os elementos de tabela XHTML, ou utilizando a formatação do código da wiki para definir a tabela. Os elementos da tabela HTML e a sua utilização são amplamente descritos em várias páginas da Web e não serão discutidos aqui. O benefício código da wiki é que a tabela é criada com símbolos de carateres que tendem a facilitar a perceção da estrutura da tabela na visualização da edição de artigos em comparação com os elementos de tabela HTML.
- ↑ HTML table cellpadding Attribute