表格可以在维基页面中创建。 一般来说,除非必要,应尽量避免使用表格。 表格的标示语言通常复杂化了页面的编辑。[1]
{| | 表格起始,必需 |
|+ | 表格 标题,选用;每张表格只能出现一次且介于表格起始与第一行 |
|- | 表格行,第一行选用 -- wiki 引擎会假设是第一行 |
! | 表格标题 储存格, 选用。 可以使用(!! )在同一行加入接续的表格标题或是单独使用(! )换新的一行 。
|
| | 表格数据调用,可选。 可以使用(|| )接续表格资料储存格或是单独使用(| )。
|
|} | 表格末尾,必要 |
||
与!!
。然而,行开头的空格会被忽略。|
或是||
,!
或是!!
,以及|+
)持有表格内容。 所以要使用单线(|
)来区隔属性与内容。 储存格内容可以都位在同一行或是换到另一行。{|
与|-
)并不直接持有内容。 在它们的属性之后请不要加入管线(|
)。 如果你在表格与行符号的属性之后错误的加入管线符号,剖析器会将之删除 以及之后任何触及该出错管线的属性!|
),可以使用<nowiki>|
</nowiki>避免成为标示语言的一部分。
在wikitext编辑器中,将光标放在你想插入表格的地方。然后在工具栏中,按“高级”,然后选择 表格按钮。
这会打开一个对话。
在对话框中,你可以选择是否启用表头行、用边框定制表格或使表格有序化。 显示的是一个预览的例子。 你也可以设置你需要的行数和列数。然后,按“插入”按钮。
By default, the following code is generated:
{| class="wikitable" style="margin:auto" |+ 标题文本 |- ! 标题文本 !! 标题文本 !! 标题文本 |- | 示例 || 示例 || 示例 |- | 示例 || 示例 || 示例 |- | 示例 || 示例 || 示例 |}
标题文本 | 标题文本 | 标题文本 |
---|---|---|
示例 | 示例 | 示例 |
示例 | 示例 | 示例 |
示例 | 示例 | 示例 |
下面这个表格没有外框与留白,但是显示了最简单的 wiki 表格标示语言的结构。
您输入的 | 您输出的 | ||||||
---|---|---|---|---|---|---|---|
{| |橘子 |苹果 |- |面包 |饼 |- |奶油 |冰淇凌 |} |
|
想要排列得更像表格,可以使用 wiki 标示语言||
将储存格分开但又并排于同一行。
如果单元格中的文本包含了换行符,可使用<br />
替代。
您输入的 | 输出效果 | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| |橘子||苹果||更多 |- |面包||饼||更多 |- |奶油||冰<br />淇淋||和<br />更多 |} |
|
如下面的Wiki标示语言,单元格包含额外空格,这不影响实际表格的呈现。
您输入的 | 输出效果 | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| | 橘子 || 苹果 || 更多 |- | 面包 || 饼 || 更多 |- | 奶油 || 冰淇凌 || 以及更多 |} |
|
您当然也可以在单元格中输入更长的文本或者更复杂的Wiki语法:
您输入的 | 输出效果 | ||
---|---|---|---|
{| |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 |} |
|
表格的头部可以通过使用“!
”(感叹号)替代“|
”(管道符号)创建。
表头通常显示为粗体,并默认居中。
您输入的 | 输出效果 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{| ! style="text-align:left;"| 项 ! 金額數量 ! 价钱 |- |橘子 |10 |7.00 |- |面包 |4 |3.00 |- |奶油 |1 |5.00 |- !总计 | |15.00 |} |
|
表格标题可以添加到任何表的顶部,如下所示。
您输入的 | 输出效果 | ||||||
---|---|---|---|---|---|---|---|
{| |+食品和配餐 |- |橘子 |苹果 |- |面包 |饼 |- |奶油 |冰淇凌 |} |
|
通过添加 class="wikitable" ,可以使表格实现:浅灰色背景、可见边框、内边距、左对齐的基本样式。
您输入的 | 输出效果 | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable" |+食品和配餐 |- |橘子 |苹果 |- |面包 |饼 |- |奶油 |冰淇凌 |} |
|
您可以在单元格可以使用HTML colspan与rowspan属性进行高级布局。
您输入的 | 输出效果 | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" !colspan="6"|购物清单 |- |rowspan="2"|麵包和奶油 |派 |小圆面包 |丹麥甜糕餅 |colspan="2"|羊角麵包 |- |奶酪 |colspan="2"|冰淇凌 |奶油 |酸奶酪 |} |
|
你可以添加HTML属性到表格。 这些属性的规范来源,请参考W3C的HTML表格规格页面。
将表格属性添加到({|
)后将应用属性到整个表格。
您输入的 | 输出效果 | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" style="text-align: center; color: green;" |橘子 |苹果 |12,333.00 |- |面包 |饼 |500.00 |- |奶油 |冰淇凌 |1.00 |} |
|
你可以将属性加诸于个别的储存格。 例如数字靠右对齐会比较好看。
您输入的 | 您输出的 | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" | 橘子 | 苹果 | style="text-align:right;" | 12,333.00 |- | 面包 | 饼 | style="text-align:right;" | 500.00 |- | 奶油 | 冰淇凌 | style="text-align:right;" | 1.00 |} |
|
当您在单行中列出多个单元格时,也可以使用单元格属性。
注意单元格是被||
分隔的,且每个单元格的属性和内容是被|
分隔的。
您输入的 | 输出效果 | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" | 橘子 || 苹果 || style="text-align:right;" | 12,333.00 |- | 面包 || 饼 || style="text-align:right;" | 500.00 |- | 奶油 || 冰淇凌 || style="text-align:right;" | 1.00 |} |
|
你也可以将属性加诸于个别的行。
您输入的 | 您输出的 | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" | 橘子 | 苹果 | style="text-align:right;"| 12,333.00 |- | 面包 | 饼 | style="text-align:right;"| 500.00 |- style="font-style: italic; color: green;" | 奶油 | 冰淇凌 | style="text-align:right;"| 1.00 |} |
|
属性可以添加到标题和标题行,如下所示。
您输入的 | 您输出的 | ||||||||
---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" |+ style="caption-side:bottom; color:#e76700;"|''食品和配餐'' |- ! style="color:green" | 水果 ! style="color:red" | 脂肪 |- |橘子 |奶油 |- |梨 |饼 |- |苹果 |冰淇凌 |} |
|
如果“border-width:”的值只有一个的话,值将应用于所有边框。
您输入的 | 您输出的 | |
---|---|---|
{|style="border-style: solid; border-width: 20px" | 您好! |} |
|
如果“border-width:”多于一个值时,四个数字分别代表顶部、右侧、底部、左侧的宽度(请记住顺时针顺序↑→↓←)。
您输入的 | 您输出的 | |
---|---|---|
{|style="border-style: solid; border-width: 10px 20px 100px 0" | 您好! |} |
|
top
, right
, bottom
这样只有三个值时,left
属性的默认值是right
(本例中为第二个值),此时左右宽度相等。top
, right
这样只有两个值时,bottom
属性的默认值是 top
(本例中为第二个值),left
属性的默认值是 right
(本例中为第二个值),此时上下宽度相等,左右宽度相等。top
: then the default value for right
is the one of top
and it is the same for bottom
and left
. The fourth width are the same and build a regular border. This is a writing shortcut.另一种定义单元格四边宽度的方法是使用 "border-left"、"border-right"、"border-top"和"border-bottom"属性:
您输入的 | 您输出的 | |
---|---|---|
{|style="border-left:solid 10px black;border-right:solid 20px black;border-top:solid 30px black;border-bottom:solid 40px black;" align="center" | 您好! |} |
|
它们在HTML 5中也是无效的。
"Cellpadding" is for setting the space between the cell wall and the cell content.
CSS 样式属性可以同时搭配或不搭配其他 HTML 属性
您输入的 | 您输出的 | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable" style="color:green; background-color:#ffffcc;" cellpadding="10" |橘子 |苹果 |- |面包 |饼 |- |奶油 |冰淇凌 |} |
|
It represents the internal margin between the contents and the border of the cell.
You type | You get | |||
---|---|---|---|---|
{|class=wikitable | style="padding: 10px" | style="padding:10px"的示例 |- | style="padding: 50px" | style="padding:50px"的示例<br/><br/>指定'''每个单元格'''的padding |- | style="padding:100px" | style="padding:100px"的示例 |} |
|
列宽可以通过如下方式添加。
您输入的:
{| class="wikitable" style="width: 85%;" | colspan="2" | 此列列宽为屏幕宽度的85%。 |- | style="width: 30%"| '''此列列宽为屏幕宽度的85%中的30%''' | style="width: 70%"| '''此列列宽为屏幕宽度的85%中的70%''' |}
您输出的:
此列列宽为屏幕宽度的85% | |
此列列宽为屏幕宽度的85%中的30% | 此列列宽为屏幕宽度的85%中的70% |
与承载数据的单元格(在表头单元格同一列的下面,或表头单元格同一行的右面)相比,表头单元格并不是十分特殊的单元格。 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:
您输入的 | 您输出的 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{| class="wikitable" |- ! scope="col"| 项目 ! scope="col"| 数量 ! scope="col"| 价格 |- ! scope="row"| 面包 | 0.3 kg | $0.65 |- ! scope="row"| 奶油 | 0.125 kg | $1.25 |- ! scope="row" colspan="2"| 总计 | $1.90 |} |
|
表格的对齐通过使用CSS实现。
表格对齐由外边距控制。
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.
为了使表格居中,你需要把两边的margin
(外边距)属性都设为auto
一个右对齐表格的例子:
您输入的 | 您输出的 | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable" style="margin-left: auto; margin-right: 0px;" | 橘子 | 苹果 |- | 面包 | 饼 |- | 奶油 | 冰淇凌 |} |
|
一个居中表格的例子:
您输入的 | 您输出的 | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable" style="margin: auto;" | 橘子 | 苹果 |- | 面包 | 饼 |- | 奶油 | 冰淇凌 |} |
|
如果您将表格与页面的右侧或左侧对齐,表格后面的文本将在表格结尾处开始,并在表格周围留下空白。
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.
您输入的 | 您输出的 | ||||||
---|---|---|---|---|---|---|---|
{| class="wikitable" style="float:right; margin-left: 10px;" | 橘子 | 苹果 |- | 面包 | 饼 |- | 奶油 | 冰淇凌 |} 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. |
单元格内容的对齐受两个不同CSS的属性控制text-align
和vertical-align
控制。
text-align
可以在表格、行或单个单元格中指定,而vertical-align
只能在单个行或单元格中指定。
您输入的 | 您输出的 | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
{| 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 |} |
|
如果你要在一行的第一个单元格中显示负数(例如 |-6 ),其中的负号可能会导致显示不正常。因为MediaWiki软件会认为你的标记并不是新单元格,而是新行 (|-)。
避免的方法是在负号前加空格(| -6
)或者使用单行单元格标记(|| -6
)。
Table borders specified through CSS rather than the border attribute will render incorrectly in a small subset of text browsers.
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.
参见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.
Click on a column or row header. Then click on the arrow. From the popup menu click on "Move" or "Delete".
From the same popup menu click on "Insert".
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.