ヘルプ:Tables/ja

提供: ひつじ小屋別館2代目
< ヘルプ:Tables
2015年1月2日 (金) 18:52時点におけるしが (トーク | 投稿記録)による版 (1版 をインポートしました)

移動先: 案内検索
PD 注意: このページを編集すると、編集内容が CC0 のもとで公開されることに同意したと見なされます。詳細はパブリック・ドメインのヘルプ ページを参照してください。
PD
</div>
For MediaWiki's database table structure, see: Manual:Database layout

ウィキページ内に (テーブル) を作成できます。全般的な規則として、どうしても必要な場合を除いて、テーブルの使用を回避するのが最善です。表のマークアップは、ページの編集を困難にしてしまうことが多いです。[1]

ウィキの表マークアップ概要

{| 表の開始, 必須
|+ 表の題(キャプション): 省略可表の開始記号と最初のの間でのみ有効
|- : 最初の行は省略可(MediaWIkiが自動的に補完)。
! 見出しセル: 省略可。連続する見出しセルは、各セルを!! または || で区切って同一行に書くか、新規行に !に続けて書く。
| データセル: 必須! 連続するセルは、各セルを || で区切って同一行に書くか、新規行に |に続けて書く。
|} 表の終了, 必須
  • 上述の各マークアップは新しい行の冒頭に書く必要があります。ただしは連続するセルを同一行に書くための二重の||!!は例外です。また新規行の冒頭にある半角空白は無視されます。
  • XHTML属性。各マークアップは、表の終了マークアップを除き、XHTML属性を与えることができます。属性はマークアップと同一行に書かなければなりません。各属性の間はシングルスペースで分離してください。
    • セルと題(| または ||! または !!|+)は内容のある部分ですので、中身と属性を区別するためにパイプ記号(|)を使用します。セルの内容は属性と同じ行に書いても、次の行に書いても構いません。
    • 表の開始と行の開始のマークアップ({||-)はそれ自身の内容はない部分です。属性指定の後にパイプ記号(|)を加えないでください。これらの開始記号のあとに加えられたパイプは、ページの生成時に直前の文字列とともに除去されるため、表が意図通り生成されなくなることがあります。
  • セルの内容は(ア)セル開始のマークアップと同一行に書く、(イ)マークアップの次以下の行に書く、のいずれも可能です。行の冒頭に使用しないと有効でないウィキマークアップ(リスト、見出し、入れ子にする表など)をセルの中に入れるためには、新しい行に書く必要があります。
    • Pipe character as content. To insert a pipe (|) character into a table, use the <nowiki>|</nowiki> escaping markup.

基本

下記のテーブルには罫線がなく、間隔の取り方もよくありませんが、最も単純なウィキマークアップによる表を示しています。

入力内容 表示結果
{|
|みかん
|りんご
|-
|おにぎり
|パン
|-
|みそ
|しょう油
|}
みかん りんご
おにぎり パン
みそ しょう油

表中の同一行のセルは、編集テキストの同一行に || (パイプ記号2個) で区切って記述できます。If the text in the cell should contain a line break, use <br/> instead.

入力内容 表示結果
{|
|Orange||Apple||more
|-
|Bread||Pie||more
|-
|Butter||Ice<br/>cream||and<br/>more
|}
Orange Apple more
Bread Pie more
Butter Ice
cream
and
more

Extra spaces within cells in the wiki markup, as in the wiki markup below, do not affect the actual table rendering.

入力内容 表示結果
{|
|  みかん    ||   りんご   ||   その他
|-
|   おにぎり    ||   パン     ||   その他
|-
|   みそ   || しょう油 ||  その他
|}
みかん りんご その他
おにぎり パン その他
みそ しょう油 その他

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
|}
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
|700
|-
|おにぎり
|4
|300
|-
|みそ
|1
|500
|-
!合計
|
|1500
|}
項目 数量 値段
みかん 10 700
おにぎり 4 300
みそ 1 500
合計 1500

注意: 見出しの '項目' に属性を付ける場合は、セパレータとして バーティカルバー '|' を使います。 '!'ではありません.

表の題

表の題は次のように加えることができます。

入力内容 表示結果
{|
|+食べものリスト
|-
|みかん
|りんご
|-
|おにぎり
|パン
|-
|みそ
|しょう油
|}
食べものリスト
みかん りんご
おにぎり パン
みそ しょう油

class="wikitable"

class="wikitable"を指定すると、基本スタイルとして (light gray background, borders, padding and align left) の属性が付加されます。

入力内容 表示結果
{| class="wikitable"
|+食べものリスト
|-
|みかん
|りんご
|-
|おにぎり
|パン
|-
|みそ
|しょう油
|}
食べものリスト
みかん りんご
おにぎり パン
みそ しょう油

HTML colspan / rowspan

セルに HTML の colspan / rowspan を使うとセルを連結できます。 それぞれ横 / 縦に連結します。

入力内容 表示結果
{| class="wikitable"
!colspan="6"|買い物リスト
|-
|rowspan="2"|パンとバター
|パイ
|バンズ
|デニッシュ
|colspan="2"|クロワッサン
|-
|チーズ
|colspan="2"|アイスクリーム
|バター
|ヨーグルト
|}
買い物リスト
パンとバター パイ バンズ デニッシュ クロワッサン
チーズ アイスクリーム バター ヨーグルト

XHTML属性

表にはXHTML属性を付加できます。XHTML属性についてもっとも信頼できる記述については、W3C の配布する HTML 4.01 仕様書の表の項目を参照してください。

表全体の属性

表の開始マークアップ({|)に続けて付加された属性は表全体に適用されます。

入力内容 表示結果
{| class="wikitable" style="text-align: center; color: green;"
|みかん
|りんご
|12,333.00
|-
|おにぎり
|パン
|500.00
|-
|みそ
|しょう油
|1.00
|}
みかん りんご 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
|}
みかん りんご 12,333.00
おにぎり パン 500.00
みそ しょう油 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
|}
Orange Apple 12,333.00
Bread Pie 500.00
Butter Ice cream 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
|}
みかん りんご 12,333.00
おにぎり パン 500.00
みそ しょう油 1.00

Simple one-pixel table border

An example of a one-pixel table border:

You type You get
{| border="1" style="border-collapse:collapse"
| Orange
| Apple
|-
| Bread
| Pie
|}
Orange Apple
Bread Pie

Border width

"border-width:" の後に数値を一つだけ書いた場合は、四方に対する指定となります。

入力内容 表示結果
{|style="border-style: solid; border-width: 20px"
|
こんにちは
|}

こんにちは

"border-width:" の後に一つ以上の数値を書いた場合、四つの数値は 上, 右, 下, 左 に対する指定となります。

入力内容 表示結果
{|style="border-style: solid; border-width: 10px 20px 100px 0"
|
こんにちは
|}

こんにちは

四つ未満の数値を書いた場合、 左を指定する数値は右の値、下を指定する数値は上の値、右を指定する数値は上ををデフォルトとします。

四方の幅を指定する別の方法に "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;font-size:90%;font-size:90%;" align="center" 
|
こんにちは
|}

こんにちは

注意 :

  • HTML 属性 (例えば "width=", "border=", "cellspacing=", "cellpadding=") 長さの単位指定を必要としません。 (ピクセル単位として扱われます) HTML属性を上書きするCSS スタイルプロパティは、ピクセルの意味の "px" のような単位指定が必要です。

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 
|}
Orange Apple
Bread Pie
Butter Ice cream

Attributes

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''
|-
|Orange
|Apple
|-
|Bread
|Pie
|-
|Butter
|Ice cream 
|}
Food complements
Orange Apple
Bread Pie
Butter Ice cream

Column width

Column width can be added as follows.

You type:

{| style="color: black; background-color: #ffffcc;" width="85%"
| colspan="2" | This column width is 85% of the screen width (and has a background color)
|-
| style="width: 30%; background-color: white;"|
'''This column is 30% counted from 85% of the screen width'''
| style="width: 70%; background-color: orange;"|
'''This column is 70% counted from 85% of the screen width (and has a background color)'''
|}

You get:

This column width is 85% of the screen width (and has a background color)
This column is 30% counted from 85% of the screen width This column is 70% counted from 85% of the screen width (and has a background color)

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"| Price
|-
! scope="row"| Bread
| 0.3 kg
| $0.65
|-
! scope="row"| Butter
| 0.125 kg
| $1.25
|-
! scope="row" colspan="2"| Total
| $1.90
|}
Item Quantity Price
Bread 0.3 kg $0.65
Butter 0.125 kg $1.25
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 
|}
Orange Apple
Bread Pie
Butter Ice cream

And a center-aligned table:

You type You get
{| class="wikitable" style="margin: auto;"
| Orange
| Apple
|-
| Bread
| Pie
|-
| Butter
| Ice cream 
|}
Orange Apple
Bread Pie
Butter Ice cream

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.
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.

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
|}
A B C
D E F
G H 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><code> and <code><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.

注意事項

負の値

新しい行の冒頭にマイナス記号を持つ負の数値(または負の数値を返す引数)があると、表が崩れてしまうことがあります。これは|-の記号が新しい表の列を開始するマークアップだからです。これを避けるためには、マイナス記号の前にスペースを挿入する(| -6)か、前のセルと同じ行に続けて || -6 のように記述してください。

See also

Notes

  1. Tables can be created using either XHTML table elements directly, or using wikicode formatting to define the table. XHTML table elements and their use are well described on various web pages and will not be discussed here. The benefit of wikicode is that the table is constructed of character symbols which tend to make it easier to perceive the table structure in the article editing view compared to XHTML table elements.
言語: English  • 日本語

案内メニュー