Help:Table/it

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search

Questa pagina non è ancora stata tradotta dall'inglese all'italiano o la sua traduzione deve ancora essere completata. Se desideri aiutarci nella traduzione sei pregato di modificare la pagina presente su meta e poi copiala sul tuo progetto. I due collegamenti sottostanti dovrebbero puntare alla pagina in inglese su meta e alla pagina in italiano su meta.

This page has not been translated from English to Italian or its translation is not yet finished. If you want to help us in translation, please edit the Italian page on Meta and copy it to this page. The two links below should point to the English page on Meta and to the Italian page on Meta.


Manuale di MediaWiki : Sommario generale —— sommario specifico per Lettori, Scrittori, Amministratori, Sviluppatori —— Altre pagine di aiuto (specifiche per questo progetto)

Questa pagina è una traduzione della corrispondente pagina del manuale in inglese di MediaWiki.

Puoi consultare (in inglese) le linee guida del manuale | la Politica editoriale

{{{{{1}}}}}

Questa pagina fornisce le informazioni sulla sintassi che serve per la creazione di tabelle-wiki in MediaWiki.

Uso della barra degli strumenti[edit]

Toolbar2.JPG

È possibile usare la barra degli strumenti di Mediawiki per creare tabelle. La barra degli strumenti è utile per generare automaticamente i codici necessari per le tabelle.

Usare il primo pulsante sulla destra della barra per inserire una tabella durante la modifica di una pagina.

Come valore predefinito, il comando inserisce il seguente testo:

{| class="wikitable"

|-

! intestazione 1

! intestazione 2

! intestazione 3

|-

| riga 1, cella 1

| riga 1, cella 2

| riga 1, cella 3

|-

| riga 2, cella 1

| riga 2, cella 2

| riga 2, cella 3

|}

Vedere : intestazione, riga, cella.

Tutorial della sintassi pipe[edit]

Intestazione di colonna 1 Intestazione di colonna 2 Intestazione di colonna 3
Intestazione di riga 1 Cella 2 Cella 3
Intestazione di riga A Cella B Cella C

Malgrado funzioni anche la sintassi delle tabelle HTML, codici speciali wikicode possono essere usati come scorciatoia per creare velocemente tabelle. I codici pipe (barra verticale) funzionano esattamente come i tag delle tabelle HTML, perciò la conoscenza del funzionamento dei codici delle tabelle HTML può aiutare alla comprensione dei codici pipe. Le scorciatoie sono le seguenti:

  • La tabella è contenuta in una coppia di parentesi graffe e di caratteri barra verticale (una pipe). Perciò usare {| per cominciare una tabella, e |} per chiuderla. Ognuno di questi codici deve stare da solo su di una riga:
{|
  qui va il codice della tabella
|}
  • Un'opzionale titolo viene incluso con una linea che comincia con una barra verticale ed un segno più "|+" e di seguito il contenuto del titolo:
{|
|+ titolo
  qui va il codice della tabella
|}
  • Per cominciare una nuova row di tabella, inserire una barra verticale e un segno meno nella stessa linea: "|-". I codici per le celle in questa riga cominceranno alla linea seguente.
{|
|+titolo
|-
  qui va il codice cella
|-
  qui va il codice cella
|}
  • Battere i codici per ogni cella di tabella alla riga seguente, cominciando con una barra:
{|
|+titolo
|-
| qui va il codice cella
|-
| le celle della riga seguente vanno qui
| qui ci sono più celle nella stessa riga
|}
  • Le celle possono essere separate andando a capo con una nuova barra, o con una doppia barra "||" sulla stessa linea. Le due scelte producono lo stesso risultato:
{|
|+titolo
|-
|Cella 1 || Cella 2 || Cella 3
|-
|Cella A 
|Cella B
|Cella C
|}
  • Se si usano le barre singole, quella che può sembrare la prima cella in effetti si rileva un modificatore di formato applicato alla cella, e il resto delle "celle" saranno fuse in una:
{| border="1"
|-
|modificatore di formato (non visualizzato)|Tutti questi |(pipe incluse)|vanno a finire dentro|la prima cella
|-
|}

che probabilmente non è ciò che si desidera:

Tutti questi |(pipe incluse)|vanno a finire dentro|la prima cella

Comunque, il modificatore di formato è utile:

{| border="1"
|-
|Cella 1 (nessun modificatore - non allineato)
|-
|align="right" |Cella 2 (allineato a destra)
|-
|}
Cella 1 (nessun modificatore - non allineato)
Cella 2 (allineato a destra)

Ricorda: non più di 2 singoli caratteri pipe su una riga!

  • una riga di intestazioni di colonnas viene identificata dall'uso di "!" invece di "|", e dall'uso di "!!" al posto di "||". Le celle di intestazione normalmente vengono rese in modo differente dalle celle normali, a seconda del browser in uso. Spesso vengono visualizzate con un carattere in grassetto e centrate.
{|
|+titolo
! Intestazione di colonna 1 !! Intestazione di colonna 2 !! Intestazione di colonna 3
|-
|Cella 1 || Cella 2 || Cella 3
|-
|Cella A
|Cella B
|Cella C
|}
  • la prima cella di un riga viene identificata come intestazione di riga cominciando la linea con "!" invece di "|", e cominciando le seguenti celle dati a capo.
{|
|+titolo
! Intestazione di colonna 1 !! Intestazione di colonna 2 !! Intestazione di colonna 3
|-
! Intestazione di riga 1 
| Cella 2 || Cella 3
|-
! Intestazione di riga A 
|Cella B
|Cella C
|}
  • Parameters opzionali possono modificare il comportamento di celle, righe, o dell'intera tabella. Per esempio si può aggiungere un bordo alla tabella:
{| border="1"
|+titolo
! Intestazione di colonna 1 !! Intestazione di colonna 2 !! Intestazione di colonna 3
|-
! Intestazione di riga 1
| Cella 2 || Cella 3
|-
! Intestazione di riga A
|Cella B
|Cella C
|}

La tabella finale verrà così mostrata:

titolo
Intestazione di colonna 1 Intestazione di colonna 2 Intestazione di colonna 3
Intestazione di riga 1 Cella 2 Cella 3
Intestazione di riga A Cella B Cella C

I parametri di tabella e di cella sono gli stessi dell'HTML, vedere [1] e Tabelle (HTML) anche se gli elementi thead, tbody, tfoot, colgroup, e col attualmente non sono supportati in MediaWiki.

Una tabella può essere utile anche se nessuna cella ha del contenuto. Per esempio, i colori di sfondo delle celle possono essere cambiato tramite i parametri di cella, rendendo la tabella una specie di diagramma, come l'm:Template talk:esempio di pentomino quadrato 8x8. Un'"immagine" in forma di tabella è molto più facile da modificare di un'immagine.

Ogni riga deve avere lo stesso numero di celle delle altre, in modo da mantenere consistente il numero delle colonne nella tabella. Per le celle vuote, usare lo spazio non divisibile &nbsp; come contenuto per assicurarsi che le celle vengano visualizzate. Per rendere visibile un carattere di pipe in una cella, usare <nowiki>|</nowiki> o &#124;.

Con i parametri di cella colspan e rowspan le celle posso attraversare diverse righe o colonne, vedere l'esempio Mélange sottostante. Comunque, ciò ha lo svantaggio che l'ordinamento non funziona più correttamente.

Esempi[edit]

Esempio semplice[edit]

I due seguenti generano lo stesso risultato. Scegli lo stile più comodo in base al numero di celle in ogni riga e al testo presente in ogni cella.

Marcatori wiki

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

Come appare nel tuo browser

A B
C D

Le "tabelline"[edit]

Marcatori wiki

Prova
Tabellina di moltiplicaione
&times; 1 2 3
1 1 2 3
2 2 4 6
3 3 6 9
4 4 8 12
5 5 10 15


Come appare nel tuo browser (vedere: Help:User_style)

Tabellina di moltiplicazione
× 1 2 3
1 1 2 3
2 2 4 6
3 3 6 9
4 4 8 12
5 5 10 15

Colore; ambito dei parametri[edit]

I seguenti sono due modi per specificare il colore del testo e dello sfondo per una cella singole. La prima forma è la preferita:

Marcatori wiki

{| 
| style="background:red; color:white" | abc
| def
| bgcolor="red" | <font color="white"> ghi </font>
| jkl
|}

Come appare nel tuo browser

abc def ghi jkl

Come gli altri parametri i colori possono essere specificati anche per l'intera riga o per l'intera tabella; i parametri di riga hanno priorità rispetto a quelli della tabella e quelli della cella rispetto a quelli di riga:

Marcatori wiki

{| style="background:yellow; color:green"
|- 
| abc || def || ghi
|- style="background:red; color:white"
| jkl || mno || pqr
|-
| stu || style="background:silver" | vwx || yz
|}

Come appare nel tuo browser

abc def ghi
jkl mno pqr
stu vwx yz

Per fare in modo che una tabella sia sfumata nello sfondo, usare style="background:none". (avvertenza: style="background:inherit", non funziona con alcuni browser, incluso IE6!)

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

Larghezza, altezza[edit]

È possibile specificare la larghezza e l'altezza di un'intera tabella, così come l'altezza di un'intera riga. Per specificare la larghezza di una colonna basta specificare la larghezza di una qualsiasi cella presente in essa. Se la larghezza non viene specificata per nessuna colonna, e/o l'altezza non viene specificata in nessuna riga, il risultato dipende dal browser.

Marcatori wiki

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

Come appare nel tuo browser

abc def ghi
jkl mno pqr
stu vwx yz

Notare che style="inline CSS" has no effect with some browsers. If compatibility is important, equivalent older constructs like width="75%" should work on more browsers.

Setting your column widths[edit]

If you wish to force column widths to your own requirements, rather than accepting the width of the widest text element in a column's cells, then follow this example. Note that wrap-around of text is forced.

{| border="1" cellpadding="2"
!width="50"|Name
!width="225"|Effect
!width="225"|Games Found In
|-
|Poké Ball || Regular Poké Ball || All Versions
|-
|Great Ball || Better than a Poké Ball || All Versions
|}
Name Effect Games Found In
Poké Ball Regular Poké Ball All Versions
Great Ball Better than a Poké Ball All Versions

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

{| border="1" cellpadding="2"
|-
|width="100pt"|This column is 100 points wide
|width="200pt"|This column is 200 points wide
|width="300pt"|This column is 300 points wide
|-
|blah || blah || blah
|}
This column is 100 points wide This column is 200 points wide This column is 300 points wide
blah blah blah

Vertical alignment[edit]

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

Row heading A 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. A shorter piece of text.
Row heading A 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. A shorter piece of text.

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

{| border="1" cellpadding="2"
|-valign="top"
|width="10%"|'''Row heading'''
|width="70%"|A longer piece of text. Lorem ipsum...
|width="20%"|A shorter piece of text.
|-valign="top"
|'''Row heading'''
|A longer piece of text. Lorem ipsum... 
|A shorter piece of text.
|}
Row heading A 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. A shorter piece of text.
Row heading A 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. A shorter piece of text.

Positioning[edit]

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

Mélange[edit]

Here's a more advanced example, showing some more options available for making up tables. Note however that with colspan and rowspan sorting does not work properly anymore.

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

Marcatori wiki

{| border="1" cellpadding="5" cellspacing="0" align="center"
|+'''An example table'''
|-
! style="background:#efefef;" | First header
! colspan="2" style="background:#ffdead;" | Second header
|-
| upper left
| &nbsp;
| rowspan=2 style="border-bottom:3px solid grey;" valign="top" |
right side
|-
| style="border-bottom:3px solid grey;" | lower left
| style="border-bottom:3px solid grey;" | lower middle
|-
| colspan="3" align="center" |
{| border="0"
|+''A table in a table''
|-
| align="center" width="150px" | [[Image:Wiki.png]]
| align="center" width="150px" | [[Image:Wiki.png]]
|-
| align="center" colspan="2" style="border-top:1px solid red; border-right:1px
          solid red; border-bottom:2px solid red; border-left:1px solid red;" |
Two Wikimedia logos
|}
|}

Come appare nel tuo browser

An example table
First header Second header
upper left  

right side

lower left lower middle
A table in a table
Wiki.png Wiki.png

Two Wikimedia logos

Floating table[edit]

Marcatori wiki

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

{| align="right" border="1"
| Col 1, row 1 
|rowspan="2"| Col 2, row 1 (and 2) 
| Col 3, row 1 
|- 
| Col 1, row 2 
| Col 3, row 2 
|}

Note the floating table to the right.   

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

What it looks like in your browser

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

Col 1, row 1 Col 2, row 1 (and 2) Col 3, row 1
Col 1, row 2 Col 3, row 2

Note the floating table to the right.

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

Nested tables[edit]

This shows one table (in blue) nested inside another table's cell2. Nested tables must start on a new line.

Marcatori wiki

{| border="1"
| &alpha;
| align="center" | cell2
{| border="2" style="background:#ABCDEF;" <!-- The nested table must be on a new line -->
| NESTED
|-
| TABLE
|}
| valign="bottom" | the original table again
|}

Come appare nel tuo browser

α cell2
NESTED
TABLE
the original table again

Combined use of COLSPAN and ROWSPAN[edit]

Marcatori wiki

{| border="1" cellpadding="5" cellspacing="0"
|-
! Column 1 || Column 2 || Column 3
|-
| rowspan="2"| A
| colspan="2" align="center"| B
|-
| C <!-- column 1 occupied by cell A -->
| D 
|-
| E
| rowspan="2" colspan="2" align="center"| F
|- 
| G <!-- column 2+3 occupied by cell F -->
|- 
| colspan="3" align="center"| H
|}

Come appare nel tuo browser

Column 1 Column 2 Column 3
A B
C D
E F
G
H

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

Centering tables[edit]

Centered tables can be achieved, but they will not "float"; that is to say, no text will appear to either side. The trick is {| style="margin: 1em auto 1em auto"

Marcatori wiki

{| class="wikitable" style="margin: 1em auto 1em auto"
|+ '''Cells left-aligned, table centered'''
! Duis || aute || irure
|-
| dolor  || in reprehenderit || in voluptate velit
|-
| esse cillum dolore || eu fugiat nulla || pariatur.
|}

Come appare nel tuo browser

Cells left-aligned, table centered
Duis aute irure
dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur.

Setting parameters[edit]

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

Marcatori wiki

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

Come appare nel tuo browser

cell1 cell2 cell3

Decimal point alignment[edit]

A method to get columns of numbers aligned at the decimal point is as follows:

Marcatori wiki

{| cellpadding="0" cellspacing="0"
|align="right"| 432 || .1
|-
|align="right"| 43 || .21
|-
|align="right"| 4 || .321
|}

Come appare nel tuo browser

432 .1
43 .21
4 .321

If the column of numbers appears in a table with cell padding or cell spacing, one can still align the decimal points without an unsightly gap in the middle. Embed a table in each number's cell and specify its column widths. Make the embedded tables' column widths the same for each cell in the column. (If decimal points are still misaligned using this method, the main table's column may be too narrow. Add a parameter to increase the column's width.)

Marcatori wiki

{|border="1" cellpadding="4" cellspacing="2"
|
{|cellpadding="0" cellspacing="0" width="100%"
|align="right" width="50%"| 432 ||width="50%"| .1
|}
|-
|
{|cellpadding="0" cellspacing="0" width="100%"
|align="right" width="50%"| 43 ||width="50%"| .21
|}
|-
|
{|cellpadding="0" cellspacing="0" width="100%"
|align="right" width="50%"| 4 ||width="50%"| .321
|}
|}

Come appare nel tuo browser

432 .1
43 .21
4 .321

In simple cases one can dispense with the table feature and simply start the lines with a space, and put spaces to position the numbers:

432.1
 43.21
  4.321

Style classes[edit]

See also Help:User style.

In the first line of table code, after the "{|", instead of specifying a style directly one can also specify a CSS class. The style for this class can be specified in various ways:

  • in the software itself, per skin (for example the class sortable)
  • collectively for all users of one wiki in MediaWiki:Common.css (for example, on this and some other projects there is the class wikitable)
  • separately per skin in MediaWiki:Monobook.css etc.
  • individually on one wiki in a user subpage
  • individually, but jointly for tables of the class concerned on all web pages, on the local computer of the user.

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

{| border="1" cellpadding="2"
|+Multiplication table
|-
! &times; !! 1 !! 2 !! 3
|-
! 1
| 1 || 2 || 3
|-
! 2
| 2 || 4 || 6
|-
! 3
| 3 || 6 || 9
|-
! 4
| 4 || 8 || 12
|-
! 5
| 5 || 10 || 15
|}
 
Multiplication table
× 1 2 3
1 1 2 3
2 2 4 6
3 3 6 9
4 4 8 12
5 5 10 15
becomes this:
{| class="wikitable"
|+Multiplication table
|-
! &times; !! 1 !! 2 !! 3
|-
! 1
| 1 || 2 || 3
|-
! 2
| 2 || 4 || 6
|-
! 3
| 3 || 6 || 9
|-
! 4
| 4 || 8 || 12
|-
! 5
| 5 || 10 || 15
|}
 
Multiplication table
× 1 2 3
1 1 2 3
2 2 4 6
3 3 6 9
4 4 8 12
5 5 10 15

simply by replacing inline CSS for the table by class="wikitable". This is because the wikitable class in MediaWiki:Common.css contains a number of table.wikitable CSS style rules. These are all applied at once when you mark a table with the class. You can then add additional style rules if desired. These override the class's rules, allowing you to use the class style as a base and build up on it:

Wiki markup

{| class="wikitable" style="font-style:italic; font-size:120%; border:3px dashed red;"
|+Multiplication table
|-
! &times; !! 1 !! 2 !! 3
|-
! 1
| 1 || 2 || 3
|-
! 2
| 2 || 4 || 6
|-
! 3
| 3 || 6 || 9
|-
! 4
| 4 || 8 || 12
|-
! 5
| 5 || 10 || 15
|}

What it looks like in your browser

Multiplication table
× 1 2 3
1 1 2 3
2 2 4 6
3 3 6 9
4 4 8 12
5 5 10 15

Notice that the table retains the gray background of the wikitable class, and the headers are still bold and centered. But now the text formatting has been overridden by the local style statement; all of the text in the table has been made italic and 120% normal size, and the wikitable border has been replaced by the red dashed border.

Of course this works only for browsers supporting inline CSS, if it's important use XHTML markup like <big> instead of "font-size:120%", or Wiki markup like ''text'' instead of "font-style:italic".

Sorting[edit]

Tables can be made sortable, see Help:Sorting. Since this can be very useful, it is wise to keep the possibilities and limitations of this feature in mind when designing a table. For example:

  • Do not divide a table into sections by subheaders spanning several rows. Instead, an extra column can be made showing the content of these headers on each row, in a short form.
  • Do not have elements spanning several columns; instead, again, repeat the content on each row, in a short form.
  • In a column of numbers, do not put text such as "ca." in front of a number (it will sort like zero), do not put text after the number, and do not put a range of numbers (it does not affect the sorting position for numeric sorting mode, and in the case of a range, the first number determines the position, but if, possibly after sorting this or another column, the element is at the top, it will induce alphabetic sorting mode). Instead, put these texts in a separate column. Alternatively, for the greatest flexibility, alphabetic sorting mode with hidden sortkeys can be used.

A long form of abbreviated content can be put as legend outside the table.

Row template[edit]

Regardless of whether wikitable format or HTML is used, the wikitext of the rows within a table, and sometimes even within a collection of tables, has much in common, e.g.:

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

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

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

Example:

Using help:table/example row template (talk, backlinks, edit)

{| class="wikitable sortable"
|-
! a
! b
! a/b
{{help:table/example row template|  50|200}}
{{help:table/example row template|   8| 11}}
{{help:table/example row template|1000| 81}}
|}

gives:

a b a/b
50 200 0.25
8 11 0.72727272727273
1000 81 12.345679012346

Table row depending on a template parameter[edit]

Wiki-syntax for a table row can be made optional using ParserFunctions. To avoid confusion between pipe characters as used in ParserFunctions, and those which are part of the table syntax, the latter are put with a special Template:! [ talk edit history links ], see Template:Table example with optional row [ talk edit history links ].

Other table syntax[edit]

Other types of table syntax that MediaWiki supports:

  1. XHTML
  2. HTML and wiki <td> syntax (Do not use)

All three are supported by MediaWiki and create (currently) valid HTML output, but the pipe syntax is the simplest, especially for people who are already familiar with HTML. Also, HTML and wiki <td> syntax will not necessarily remain browser-supported in the upcoming future, especially on handheld internet-accessible devices.

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

Comparison of table syntax[edit]

 XHTML HTML & Wiki-td Wiki-pipe
Table <table></table> <table></table>
{|
|}
Caption <caption>caption</caption> <caption>caption</caption>
|+ caption
Row <tr></tr> <tr>
|-
Data cell

<td>cell1</td>
<td>cell2</td>

<td>cell1
<td>cell2

| cell1
| cell2
Data cell <td>cell1</td> <td>cell2</td> <td>cell3</td> <td>cell1 <td>cell2 <td>cell3
| cell1 || cell2 || cell3
Header cell <th>heading</th> <th>heading
! heading
Sample table
1 2
3 4
<table>
   <tr>
      <td>1</td>
      <td>2</td>
   </tr> 
   <tr>
      <td>3</td> 
      <td>4</td> 
   </tr>
</table>
<table>
   <tr>
      <td> 1 <td> 2
   <tr>
      <td> 3 <td> 4
</table>
{| 
| 1 || 2
|- 
| 3 || 4
|}
Sample table
1 2
3 4
5 6
<table>
   <tr>
      <td>1</td>
      <td>2</td>
   </tr> 
   <tr>
      <td>3</td>
      <td>4</td>
   </tr>
   <tr>
      <td>5</td>
      <td>6</td>
   </tr>
</table>
<table>
   <tr>
      <td> 1 <td> 2
   <tr>
      <td> 3 <td> 4
   <tr>
      <td> 5 <td> 6
</table>
{| 
| 1 || 2 
|- 
| 3 || 4 
|- 
| 5 || 6 
|}
Pros
  • Can be previewed/debugged with any XHTML editor
  • Can be formatted for easier reading
  • Well-known
  • Insensitive to newlines
  • No characters like "|" which can collide with template and parser function syntax
  • Can be previewed/debugged with any HTML editor
  • Can be formatted for easier reading
  • Well-known
  • Takes less space than XHTML
  • Insensitive to newlines
  • No characters like "|" which can collide with template and parser function syntax
  • Easy to write
  • Easy to read
  • Takes little space
Cons
  • Tedious
  • Takes a lot of space
  • Difficult to read quickly
  • May not have browser support in future
  • Unfamiliar syntax
  • Rigid structure
  • Cannot be indented
  • Text (as in HTML tags) may be easier for some people to read than series of pipes, plus signs, exclamation marks, etc.
  • Is nothing more than a shortcut for HTML-style tags. Not easily understood by those unfamiliar with HTML table concepts
  • Assigning to a template parameter a value containing "|" requires Template:!
  • Sensitive to newlines, although these are not always easy to control, see Help:Newlines and spaces; thus a workaround is needed such as the code &nbsp;
 XHTML HTML & Wiki-td Wiki-pipe

See also Template talk:For#Tables.

Pipe syntax in terms of the HTML produced[edit]

The pipe syntax, developed by Magnus Manske, substitutes pipes (|) for HTML. There is an on-line script which converts html tables to pipe syntax tables.

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

Tables[edit]

A table is defined by {| ''params'' |} which equals <table ''params''>Insert non-formatted text here </table>

Careful: You must include the space between {| and params, or the first parameter gets ignored.

Rows[edit]

<tr> tags will be generated automatically for the first row. To start a new row, use

|-

which results in

<tr>

Parameters can be added like this:

|- params

which results in

<tr params>

Note:

  • <tr> tags will be automatically opened at the first <td> equivalent
  • <tr> tags will be automatically closed at <tr> and </table> equivalents

Cells[edit]

Cells are generated either like this:

|cell1
|cell2
|cell3

or like this:

|cell1||cell2||cell3

which both equal

<td>cell1</td><td>cell2</td><td>cell3</td>

so "||" equals "newline" + "|"

Parameters in cells can be used like this:

|params|cell1||params|cell2||params|cell3

which will result in

<td params>cell1</td>
<td params>cell2</td>
<td params>cell3</td>

Headers[edit]

Functions the same way as TD, except "!" is used instead of the opening "|". "!!" can be used instead of "||". Parameters still use "|", though! Example:

!params|cell1

Captions[edit]

A <caption> tag is created by

|+ Caption

which generates

<caption>Caption</caption>

You can also use parameters:

|+ params|Caption

which will generate

<caption params>Caption</caption>

Displaying the table code which generates a table[edit]

The code for a simple wiki markup table inside a Code box can be seen below.

{| border="5" cellspacing="5" cellpadding="2"
| style="text-align: center;" | [[Image:gnome-system.png]]
|-
! Computer
|-
| Processor Speed: 1.8 GHz
|}

Above code produces/displays the table below:

Gnome-system.png
Computer
Processor Speed: 1.8 GHz

Below code, generated and displayed the above table's Code box code itself, on the screen and web page, inside a blue colored dashed bordered rectangular box.

 
<pre>
{| border="5" cellspacing="5" cellpadding="2"
| style="text-align: center;" | [[Image:gnome-system.png]]
|-
! Computer
|-
| Processor Speed: 1.8 GHz
|}
</pre>
 

Note that, HTML tag <pre> was used to achieve displaying the above codes and the Code box.

Other alternatives to display table code[edit]

In most cases, when a code line is longer than the web browser window's width, then a scrolling bar appears at bottom, to let the viewer slide to the right side (and also left side) to see the rest of the codes, because, the use of <pre> tag causes the code line to remain intact, unless an EOL (CR/LF) hidden character is reached in that text line. But having to slide or scroll to the right or left for viewing the full codes is often not comfortable to many readers. To solve such problem, using the <p>, <tt> and <br /> HTML tags, are better than using the <pre> tag, as those will limit the length of a line of code according the available space in the web browser's window and therefor will not result in the need to move the scroll-bar right (or left) for viewing. By placing the codes inside the <tt>...</tt> HTML tags, codes are displayed with a fixed width text/font, (like the <pre> tag uses) for easier reading. HTML tag <br /> is used to display (or bring) next line of codes, starting from the next line. HTML tag <p> along with its CSS style properties, is used to create the blue colored dashed bordered rectangular box (Code box) around the codes, (like the HTML <pre> tag, which gets these properties from the main.css stylesheet file).

An example of table code with a long line is:

{| border="5" cellspacing="5" cellpadding="2"
| style="text-align: center;" | [[Image:gnome-system.png]]
|-
! Computer
|-
| style="color: yellow; background-color: green;" | Processor Speed: <span style="color: white;"> 1.8 GHz </span>
|}

producing the below table:

Gnome-system.png
Computer
Processor Speed: 1.8 GHz

Code box above the table has the auto line wrapping feature enabled. Note the long line (the sixth line from top) inside the codes, which is wrapped inside the Code box. This Code box and the codes, can be displayed by using below codes in the edit box.

<p style="padding: 1em; border: 1px dashed #2f6fab; color: Black; background-color: #f9f9f9; line-height: 1.1em;"> <tt>
<nowiki>{|</nowiki> border="5" cellspacing="5" cellpadding="2" <br />
| style="text-align: center;" | <nowiki>[[</nowiki>Image:gnome-system.png]] <br />
|- <br />
! Computer <br />
|- <br />
| style="color: yellow; background-color: green;" | Processor Speed: <nowiki><span style="color: white;"></nowiki> 1.8 GHz <nowiki></span></nowiki> <br />
<nowiki>|}</nowiki> <br />
</tt> </p>

See the above codes, note that, <nowiki>...</nowiki> tags were used to disable wiki markup codes for beginning a table ({|), ending a table (|}), start of an image displaying ([[), or a hyperlink, etc. All wiki & HTML markup codes need to be disabled by enclosing them inside the <nowiki>...</nowiki> tags. If these codes were to be displayed inside another table, then, each | (pipe) & ! (Exclamation mark) symbol also needed to be enclosed inside the <nowiki> tags. Note that, the longer line is automatically wrapped according to the width of the web browser's window, inside the Code box.

Alternatively, we can replace each | (pipe symbol) character with &#124; (HTML decimal entity code), replace each ! (exclamation mark) with &#33; code, replace { (beginning curly/second bracket) with &#123; and we may replace } (closing curly/second bracket) with &#125; code. Also replace the < (less than sign, or beginning angle bracket) with &#60; numeric entity code or, replace it with &lt; (HTML symbol entity code). For more on HTML decimal or hexadecimal numeric entity codes, please see w:Windows Alt codes. To display the wiki image markup code, we should replace the [ (beginning square/third bracket) with &#91; and we may replace ] (closing square/third bracket) with &#93;. When we are replacing characters with their numeric enitity codes, we are actually disabling their normal functionality, so we can display them on the web page(s).

By using the numeric entity codes, mentioned in the above paragraph, below codes can display the above Code box in another alternative (better) way. Note that, the longer line is automatically wrapped, without exceeding the browser window's width, inside the below Code box.   
Gnome-system.png
Computer
Processor Speed: 1.8 GHz

<p style="padding: 1em; border: 1px dashed #2f6fab; color: Black; background-color: #f9f9f9; line-height: 1.1em;"> <tt>
&#123;&#124; border="5" cellspacing="5" cellpadding="2" <br />
&#124; style="text-align: center;" &#124; &#91;&#91;Image:gnome-system.png]] <br />
&#124;- <br />
&#33; Computer <br />
&#124;- <br />
&#124; style="color: yellow; background-color: green;" &#124; Processor Speed: &#60;span style="color: red;"> 1.8 GHz &#60;/span> <br />
&#124;&#125; <br />
</tt> </p>

See also disabling wikitext interpretation and/or reformatting.

See also[edit]

External links[edit]


Links to other help pages[edit]

Help contents
Meta · Wikinews · Wikipedia · Wikiquote · Wiktionary · Commons: · Wikidata · MediaWiki · Wikibooks · Wikisource · MediaWiki: Manual · Google
Versions of this help page (for other languages see further)
What links here on Meta or from Meta · Wikipedia · MediaWiki
Reading
Go · Search · Stop words · Namespace · Page name · Section · Backlinks · Redirect · Category · Image page · Special pages · Printable version
Tracking changes
Recent changes (enhanced) | Related changes · Watching pages · Diff · Page history · Edit summary · User contributions · Minor edit · Patrolled edit
Logging in and preferences
Logging in · Preferences · User style
Editing
Starting a new page · Advanced editing · Editing FAQ · Edit toolbar · Export · Import · Shortcuts · Edit conflict · Page size
Referencing
Links · URL · Piped links · Interwiki linking · Footnotes
Style and formatting
Wikitext examples · CSS · Reference card · HTML in wikitext · Formula · List · Table · Sorting · Colors · Images and file uploads
Fixing mistakes
Show preview · Testing · Reverting edits
Advanced functioning
Expansion · Template · Advanced templates · Parser function · Parameter default · Variable · System message · Substitution · Array · Calculation · Embed page
Others
Special characters · Renaming (moving) a page · Preparing a page for translation · Talk page · Signatures · Sandbox · Legal issues for editors
Lingua: English · العربية · български · dansk · Deutsch · Esperanto · español · euskara · euskara · suomi · français · galego · italiano · 日本語 · Nederlands · polski · русский · shqip · Tiếng Việt · 中文


Manuale di MediaWiki : Sommario generale —— sommario specifico per Lettori, Scrittori, Amministratori, Sviluppatori —— Altre pagine di aiuto (specifiche per questo progetto)

Questa pagina è una traduzione della corrispondente pagina del manuale in inglese di MediaWiki.

Puoi consultare (in inglese) le linee guida del manuale | la Politica editoriale

{{{{{1}}}}}


Links to other help pages[edit]

Help contents
Meta · Wikinews · Wikipedia · Wikiquote · Wiktionary · Commons: · Wikidata · MediaWiki · Wikibooks · Wikisource · MediaWiki: Manual · Google
Versions of this help page (for other languages see further)
What links here on Meta or from Meta · Wikipedia · MediaWiki
Reading
Go · Search · Stop words · Namespace · Page name · Section · Backlinks · Redirect · Category · Image page · Special pages · Printable version
Tracking changes
Recent changes (enhanced) | Related changes · Watching pages · Diff · Page history · Edit summary · User contributions · Minor edit · Patrolled edit
Logging in and preferences
Logging in · Preferences · User style
Editing
Starting a new page · Advanced editing · Editing FAQ · Edit toolbar · Export · Import · Shortcuts · Edit conflict · Page size
Referencing
Links · URL · Piped links · Interwiki linking · Footnotes
Style and formatting
Wikitext examples · CSS · Reference card · HTML in wikitext · Formula · List · Table · Sorting · Colors · Images and file uploads
Fixing mistakes
Show preview · Testing · Reverting edits
Advanced functioning
Expansion · Template · Advanced templates · Parser function · Parameter default · Variable · System message · Substitution · Array · Calculation · Embed page
Others
Special characters · Renaming (moving) a page · Preparing a page for translation · Talk page · Signatures · Sandbox · Legal issues for editors
Lingua: English · العربية · български · dansk · Deutsch · Esperanto · español · euskara · euskara · suomi · français · galego · italiano · 日本語 · Nederlands · polski · русский · shqip · Tiếng Việt · 中文