Help:表

From mediawiki.org
This page is a translated version of the page Help:Tables and the translation is 91% complete.
PD 注意: このページを編集すると、編集内容が CC0 のもとで公開されることに同意したと見なされます。詳細はパブリック・ドメインのヘルプ ページを参照してください。 PD
Tables はこのページに転送されています。MediaWiki のデータベース テーブルの構造は、Manual:データベースのレイアウト を参照してください 。

ウィキ ページでは表 (table) を作成できます。 原則として、必要がなければテーブルの使用を避けるのが最善です。 テーブルのマークアップはしばしばページの編集を煩雑にさせます。[1]

テーブルのウィキ文法の概要

{| 表の開始必須
|+ 表のキャプション省略可能表の開始表の行の間でしか記述できない。
|- 表の行最初の行については省略可能。(明示されなくとも、)ウィキエンジンは最初の行を推定します。
! 表のヘッダーセル、省略可能。 同じ行に続く表のヘッダーセルは、エクスクラメーションマーク2つ (!!) で区切って同じ行に記述するか、エクスクラメーションマーク1つ (!) を新しい行の先頭に記述することで、表現できます。
| 表のデータセル、省略可能。 同じ行に続く表のデータセルは、バーティカルバー2つ (||) で区切って同じ行に記述するか、バーティカルバー1つ (|) を新しい行の先頭に記述することで、表現できます。
|} 表の終了必須
  • 上記のマークは必ず行頭で指定する必要があり、例外は縦棒2本||!!を使い、特定の行に選択的に連続するセルを追加する場合です。しかしながら、行頭の空きスペース文字は無視されます。
  • HTML の属性。 表の終わりの指定以外は、1以上のHTML 属性を受け入れます。 属性とマークは同じ行に記述します。 属性どうしの間は半角空きスペースで区切ります。
    • セルとキャプション (| もしくは ||!もしくは!!|+) に内容を書き込めます。 そこで、属性と内容の区切り記号は縦棒1本を使います (|)。 セルの内容は同じ行に続くか、下方の数行に続くか、どちらの場合もあります。
    • 表であることを示す記号、行が変わることを示す記号 ({||-) には、内容を直接、表示させることができません。 選択的に加えた属性の後に縦棒 (パイプ記号 |) を入れては ダメ です。 テーブルマークや行マークの属性の後に誤ってパイプを追加した場合、パーサーはそのパイプと最終的な属性を削除してしまいます。
  • Content may (a) follow its cell mark on the same line after any optional HTML attributes or (b) on lines below the cell mark.

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.

To insert a pipe (|) character into a table, use the <nowiki>|</nowiki> escaping markup.


基礎

Create a table with editor toolbar

In wikitext editor, place the caret where you want to insert a table. Then, in the toolbar, press “上級”, then choose 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 “挿入” button.

By default, the following code is generated:

Wikicode:
{| class="wikitable" style="margin:auto"
|+ キャプション文
|-
! 見出しテキスト !! 見出しテキスト !! 見出しテキスト
|-
| セル内のテキスト || セル内のテキスト || セル内のテキスト
|-
| セル内のテキスト || セル内のテキスト || セル内のテキスト
|-
| セル内のテキスト || セル内のテキスト || セル内のテキスト
|}
Result:
キャプション文
見出しテキスト 見出しテキスト 見出しテキスト
セル内のテキスト セル内のテキスト セル内のテキスト
セル内のテキスト セル内のテキスト セル内のテキスト
セル内のテキスト セル内のテキスト セル内のテキスト

Minimal syntax

以下のテーブルは罫線と十分な余白を欠いていますが、最も簡単な表構造のウィキ文法を示すために使っています。

記述例 表示例
{|
|オレンジ
|りんご
|-
|パン
|パイ
|-
|バター
|アイスクリーム
|}
オレンジ りんご
パン パイ
バター アイスクリーム

同じ行のセルは、||で区切って、一行で書くことができます。 もし、セルの中に改行を含める必要があれば、‎<br />を代わりに使ってください。

入力 出力
{|
|オレンジ||りんご||など
|-
|パン||パイ||など
|-
|バター||アイス<br />クリーム||そして<br />まだまだ
|}
オレンジ りんご など
パン パイ など
バター アイス
クリーム
そして
まだまだ

以下のウィキマークアップにあるような、セルの中の余分な半角スペースは、表の形成に影響を与えません。

入力 出力
{|
|  オレンジ || りんご || など
|-
|   パン || パイ || など
|-
|   バター || アイスクリーム || そしてまだまだ
|}
オレンジ りんご など
パン パイ など
バター アイスクリーム そしてまだまだ

長い文章を入れたり、セルの中で別なウィキ構文を使うこともできます。

入力 出力
{|
|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
|7.00
|-
|パン
|4
|3.00
|-
|バター
|1
|5.00
|-
!合計
|
|15.00
|}
品目 個数 価格
オレンジ 10 7.00
パン 4 3.00
バター 1 5.00
合計 15.00
HTMLの属性をセルで使うときは、「品目」のセルのように、“|” を区切りとして使います。 “!” ではありません。

キャプション

表のキャプションは、以下のように、あらゆる表の一番上に追加することができます。

入力 出力
{|
|+食品の補完
|-
|オレンジ
|りんご
|-
|パン
|パイ
|-
|バター
|アイスクリーム
|}
食品の補完
オレンジ りんご
パン パイ
バター アイスクリーム

class="wikitable"

基本スタイル(薄い灰色の背景と罫線、余白と文字の左寄せ)は、class="wikitable" を追加することで実現できます。

入力 出力
{| class="wikitable"
|+食品の補完
|-
|オレンジ
|りんご
|-
|パン
|パイ
|-
|バター
|アイスクリーム
|}
食品の補完
オレンジ りんご
パン パイ
バター アイスクリーム

HTML の colspan と rowspan

高度なレイアウトのために、HTMLのcolspanrowspan 属性をセルに利用できます。

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

HTML の属性

HTML 属性をテーブルに適用できます。 For the authoritative source on HTML attributes, see the W3C's HTML Specification page on tables.

表の属性

Placing attributes after the table start tag ({|) applies attributes to the entire table.

入力 出力
{| class="wikitable" style="text-align: center; color: green;"
|オレンジ
|りんご
|12,333.00
|-
|パン
|パイ
|500.00
|-
|バター
|アイスクリーム
|1.00
|}
オレンジ りんご 12,333.00
パン パイ 500.00
バター アイスクリーム 1.00

セルの属性

You can put attributes on individual cells. 例えば、数字は右寄せにした方が見栄えが良い場合があります。

入力 出力
{| 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 |.

入力 出力
{| 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 put attributes on individual rows, too.

入力 出力
{| 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

キャプションとヘッダーで属性を表示

キャプションとヘッダーには、以下のように属性を付加することができる。

入力 出力
{| class="wikitable"
|+ style="caption-side:bottom; color:#e76700;"|''食品の補完''
|-
! style="color:green" | 果物
! style="color:red" | 脂肪
|-
|オレンジ
|バター
|-
|洋梨
|パイ
|-
|りんご
|アイスクリーム
|}
食品の補完
果物 脂肪
オレンジ バター
洋梨 パイ
りんご アイスクリーム

ボーダー幅

If "border-width:" has only one number, it is for all four border sides:

入力 出力
{|style="border-style: solid; border-width: 20px"
|
こんにちは
|}

こんにちは

If "border-width:" has more than one number, the four numbers are for top, right, bottom, left (REMEMBER clockwise order ↑→↓←):

入力 出力
{|style="border-style: solid; border-width: 10px 20px 100px 0"
|
こんにちは
|}

こんにちは

When there are fewer than 4 values :
  • three values i.e. top, right, bottom: then the default value for left is the one of right (second value). Width is then the same on left and right side.
  • two values i.e. top, right: then the default value for bottom is the one of top (first value), and left by default is assigned the value of right (second value). Width on top is then the same as on bottom; width on left is the same as on right.
  • 1 つの値、すなわち top の場合: right の既定値は top のものとなり、bottomleft も同じです。4 番目の幅は同じで、通常のボーダーを構築します。これはライティングのショートカットです。

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":

入力 出力
{|style="border-left:solid 10px black;border-right:solid 20px black;border-top:solid 30px black;border-bottom:solid 40px black;" align="center"
|
こんにちは
|}

こんにちは

The HTML attributes (such as "width=", "border=", "cellspacing=", "cellpadding=") do not need any length unit (the pixel unit is assumed). また、HTML5では無効となります。

"Cellpadding" is for setting the space between the cell wall and the cell content.

[2] CSS のスタイルプロパティ(HTML の属性を上書きする)では、ピクセルに対して「px」のような長さの単位を(値が 0 でない場合)明示的に指定する必要があります。

HTMLの属性やCSSのスタイルを使って

CSS style attributes can be added with or without other HTML attributes.

入力 出力
{| class="wikitable" style="color:green; background-color:#ffffcc;" cellpadding="10"
|オレンジ
|りんご
|-
|パン
|パイ
|-
|バター
|アイスクリーム
|}
オレンジ りんご
パン パイ
バター アイスクリーム

Padding

It represents the internal margin between the contents and the border of the cell.

入力内容 出力結果
{|class=wikitable
| style="padding: 10px" | style="padding:10px" の例
|-
| style="padding: 50px" | style="padding:50px" の例<br/><br/>Specify the padding on '''EACH CELL'''
|-
| style="padding:100px" | style="padding:100px" の例
|}
style="padding:10px" の例
style="padding:50px" の例

Specify the padding on EACH CELL
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%カウントされます

テーブルヘッダーセルのアクセシビリティ

表のヘッダーセルは、どの表のデータセルに適用されるか(同じ行の右側のセル、または同じ列の下のセル)を明示的に指定しない。 視覚的な2D環境でテーブルをレンダリングした場合、通常、これは容易に推測できる。

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
|}
品目 重量 価格
パン 0.3 kg $0.65
バター 0.125 kg $1.25
合計 $1.90

配置

表の配置

テーブルの整列はCSSを使用して実現されています。 テーブルの配置は、マージンによって制御されます。 片側に固定されたマージンは、反対側のマージンがautoと定義されている場合、その側にテーブルが揃うようになります。 テーブルをセンター揃えにするには、両方のマージンをautoに設定する必要があります。

For example, a right-aligned table:

入力 出力
{| class="wikitable" style="margin-left: auto; margin-right: 0px;"
| オレンジ
| りんご
|-
| パン
| パイ
|-
| バター
| アイスクリーム
|}

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:

入力 出力
{| class="wikitable" style="margin: auto;"
| オレンジ
| りんご
|-
| パン
| パイ
|-
| バター
| アイスクリーム
|}

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.

表とテキストの回り込み

表をページの右側または左側に配置した場合、表の後に来るテキストは表の端から始まり、表の周りには何もない状態になります。 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. float パラメータを指定すると余白で表の配置を調整しません。周囲の文字列との間隔を指定できます。

入力 出力
{| 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.

セルの内容の配置

セルの内容の配置は、2 つの異なる CSS プロパティ text-alignvertical-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
|}
A B C
D E F
G H I


注意

負の数値

新しい行の最初のセルに、マイナス記号で始まる負の数値 (または負の数値に評価されるパラメーター) を使用すると、表が壊れる場合があります。文字列 |- が、表のセルとしてではなく、表の行のウィキ マークアップと解釈されるためです。 これを回避するには、値の前に半角空白を挿入するか (| -6)、またはインラインのセルのマークアップ (|| -6) を使用します。

CSS と属性

表の枠線は変換エラーを避けるため CSS で指定します。属性を入力するとテキストブラウザの小さなサブセットでは正しく表示されません。

列、列と行それぞれの集合によく使われる値

現在、MediaWiki では表の構文における共通の属性の指定はサポートされていません。列(HTML要素‎<col />)、列グループ(HTML要素‎<colgroup>‎</colgroup>)あるいは行グループ(HTML要素‎<thead>‎</thead>‎<tbody>‎</tbody>‎<tfoot>‎</tfoot>)のどれも未対応です。 これら標準の HTML 要素は、HTML 要素でも XHTML 要素でも使用できません。

表の行あるいはセル (ヘッダー行もデータ行も) は単一の暗黙の行グループ (HTML 要素 ‎<tbody>‎</tbody>) 内でレンダリングされ、属性もスタイルも指定しません。

ビジュアルエディター (VE) と表の操作

関連項目: Help:ビジュアルエディター/利用者ガイド

Phab: T108245: "Fully support basic table editing in the visual editor" を参照してください。 タスクの一覧を参照しましょう。レ点は完了した印です。技術の専門用語を読んでも、具体的に改良された点や、どんな機能が追加されたか理解するのは難しいかもしれません。そこで下欄に説明文を記入してください。

列や行の移動、削除

列もしくは行のヘッダをクリック。 つづいて矢印をクリック。 ポップアップメニューの「移動」もしくは「削除」をクリック。

空白の列もしくはカラムの挿入

同じポップアットメニューの「挿入」をクリック。

ウェブ上の表をビジュアルエディタにコピーする

ウェブサイト上の表をコピーしてビジュアルエディタ (VE)にペーストすることは可能です。 安全に実施する方法として、下書きページ(サンドボックスる)を使い、ウィキテキストのコードが正しいかどうかソースモードで表示すると、ビジュアルエディタに移したときのが正しいかプレビューで確認できます。

Helping tools

  • Excel2Wiki allows you to copy a spreadsheet from Excel, Apache OpenOffice, LibreOffice, or Gnumeric to convert it into wikicode table.

関連項目

注記

  1. テーブルは、HTMLの table 要素を直接使っても、ウィキ文法によっても作ることができます。 HTMLの table 要素とその使い方については、様々なウェブページでしっかりと説明されているので、ここでは言及しません。 ウィキコードを使用する利点は、ページの編集ビューで見たときに、文字列や記号で記述してあると表要素をHTMLで記述するよりも、表の構造を比較的理解しやすいことです。
  2. HTML table cellpadding Attribute