Grid[{{expr11,expr12,…},{expr21,expr22,…},…}]
exprijを二次元格子に並べてフォーマットするオブジェクトである.
Grid
Grid[{{expr11,expr12,…},{expr21,expr22,…},…}]
exprijを二次元格子に並べてフォーマットするオブジェクトである.
詳細とオプション
- ノートブックでは,
で列を,
で行を追加することで,2Dのレイアウトで式が入力できる.デフォルトでは,このレイアウトを評価するとネストしたリストになる.Grid[layout]を使うとレイアウトを保存したGridを作ることができる.
を使ってGrid中の次のプレースホルダに移動することができる.
でGrid外へ移動することができる.- Grid[…]ではStandardFormやTraditionalFormにおけるように格子がフォーマットされる.
- InputFormでは,Grid[…]はそのままGrid[…]としてフォーマットする.
- Normal[grid]は格子を構成しているリストのリストを抽出する.
- exprijは任意の式(グラフィックスおよびコントロールを含む)でよい.
- Gridの要素へのテキスト入力は文字列で行える.Text["string"]またはStyle["string","style"]で特定のスタイルを指定することができる.
- Grid[{list1,list2,…}]中の listiすべてが同じ長さである必要はない.短い行の最後には空白スペースが置かれる.
- 例えばGrid[{{e,SpanFromLeft,SpanFromLeft},…}]を使って要素 e が格子上の複数の位置を結合するように指定することができる.
- 次は,特定の位置を結合する指定である.
-
SpanFromLeft 左から結合する SpanFromAbove 上から結合する SpanFromBoth 左と上の両方から結合する - 配列の長方形の部分を{{e,SpanFromLeft,SpanFromLeft,…}, {SpanFromAbove,SpanFromBoth,SpanFromBoth,…},…}にすることで,特定の要素を複数行と複数列の両方に結合することができる.
- ノートブックでは,「要素の結合」メニュー項目で,格子中の選択した要素を結合して単一の結合要素にすることができる.
- 次のオプションを使うことができる.
-
Alignment {Center,Baseline} 項目の水平方向と垂直方向の整列 AllowedDimensions Automatic 行数と列数についての制限 AutoDelete False 要素が1つだけ残った場合に格子の構造をなくしてしまうかどうか Background None 使用する背景色 BaselinePosition Automatic 周囲のテキストのベースラインと何を揃えるか BaseStyle {} 格子のベーススタイル指定 DefaultElement "" 空の項目にどのような要素を挿入するか Dividers {} 格子中のどこに区切り線を引くか Frame None 格子のどこに枠を描くか FrameStyle Automatic 枠線のスタイル ItemSize Automatic 各項目の高さと幅 ItemStyle None 行と列のスタイル Spacings Automatic 水平間隔と垂直間隔 - Frameの一般的な設定値には次のようなものがある.
-
None 枠は描かない True 格子全体の周囲に枠を描く All 格子内の各項目の周囲に枠を描く {All, False} すべての水平位置に枠を描く(列線) {False, All} すべての垂直位置に枠を描く(行線) - オプションAlignment,Background,Frame,ItemSize,ItemStyleの設定は,異なる要素に別々に適用するように,次のように与えることができる.
-
spec すべての項目に spec を適用する {specx} 連続する水平位置に specxを適用する {specx,specy} 連続する水平位置および垂直位置に speckを適用する {specx,specy,rules} 個々の i,j 要素への明示的な規則の適用も許す - speckの取り得る形
-
{s1,s2,…,sn} まず s1から snまでを使い,次いでデフォルトを使う {{c}} すべての場合に c を使う {{c1,c2}} c1と c2を交互に使う {{c1,c2,…}} すべての ciを循環させる {s,{c}} まず s を使い,続いて c を繰り返し使う {s1,{c},sn} まず siを使い,続いて c を繰り返し使うが,最後には snを使う {s1,s2,…,{c1,c2,…},sm,…,sn} まず siの最初の連続を使い,続いて ciを循環的に使い,それから siの最後の連続を使う {s1,s2,…,{},sm,…,sn} 最初に siの最初の連続を使い,最後の連続を最後に使う {i1->v1,i2->v2,…} 位置 ikで何を使うかを指定する {spec,rules} rules を使って specの指定を無効にする - {s1,s2,…,{…},sm,…,sn}という形の設定では,格子中の項目数以上の siが指定されている場合は,始まりの方の siは始まりの方の項目に使われ,終りの方の siは終りの方の項目に使われる.
- Alignment,Background,Frameのような設定は,Itemを使って,実質的に格子中の個々の項目について指定することができる.
- デフォルト設定のItemSize->Automaticでは,Gridは必要があれば要素を複数行に分割する.
- Gridは,明示的なImageSize設定がしてあるグラフィックスその他のオブジェクトのサイズを変更することはない.
- 特定の方向に n 個の要素を持つ格子の場合,DividersとSpacingsで,最初の要素の前から最後の要素の後ろまでの n+1個の要素と要素の間の部分の設定をすることができる.
- DividersとSpacingsの設定には次のような形式が使える.
-
spec 要素と要素の間のすべての部分に spec を適用する {specx,specy} 連続する水平方向と垂直方向の間の部分に specx, specyを適用する - speciは,Alignment,Background,その他の項目指向のオプションと同じ形を取ることができる.
- BaselinePositionには次の設定値を使うことができる.
-
Axis 格子中の中央行の軸 Baseline 格子中の中央行のベースライン Bottom 格子全体の一番下 Center 上と下の中間 Top 格子全体の一番上 {{i,j},pos} 要素 i,j 中の位置 pos pos->ref pos が ref と並ぶようにするベースラインオフセット - BaselinePositionはデフォルトでCenter->Axisであるとみなされる.
- BaseStyleの設定値は,一般に現行スタイルシートの"Grid"スタイルで与えられるデフォルトスタイルに加えられる.
例題
すべて開く すべて閉じる例 (3)
Grid[{{a, b, c}, {x, y, z}}]Grid[{{a, b, c}, {x, y ^ 2, z ^ 3}}, Frame -> All]Textを使って格子要素をテキストとしてフォーマットする:
Text[Grid[{{"第一", "第二"}, {"第三", "第四"}}]]スコープ (42)
格子の中の要素 (5)
Gridには,任意の大きさの要素を入れることができる:
Grid[Table[j! / (i + 11), {i, 3}, {j, 12}]]Gridには,グラフィックスやその他の任意の式を入れることができる:
Grid[Table[Graphics[Circle[], ImageSize -> 25], {2}, {10}]]Gridには,アクティブなコントロールを入れることができる:
Grid[Table[Checkbox[], {2}, {8}]]u = Table[i!, {i, 10}]Grid[{u}]Gridを使って,行がない,空行,不揃いな行を持った格子を作ることができる:
{Grid[{}], Grid[{{}}], Grid[{{}, {1}, {1, 2}, {1, 2, 3}}]}枠と格子線 (5)
Grid[Table[x, {3}, {7}], Frame -> True]Grid[Table[x, {3}, {7}], Frame -> All]Grid[Table[x, {3}, {7}], Frame -> All, FrameStyle -> Red]Grid[Table[x, {3}, {7}], Frame -> {{True}, {True}}]Grid[Table[x, {3}, {7}], Frame -> {{Red}, {Green}}]Grid[Table[x, {3}, {7}], Dividers -> {All, False}]Grid[Table[x, {3}, {7}], Dividers -> {False, All}]Grid[Table[x, {3}, {7}], Dividers -> {{False, False, True}, {False, True}}]要素のスパン (3)
Grid[{{1, 2, 3}, {4, SpanFromLeft, 6}, {7, 8, 9}}, Frame -> All]Grid[{{1, 2, 3}, {4, SpanFromLeft, SpanFromLeft}, {7, 8, 9}}, Frame -> All]Grid[{{1, 2, 3}, {4, SpanFromAbove, 6}, {7, 8, 9}}, Frame -> All]Grid[{{1, 2, 3}, {4, SpanFromAbove, 6}, {7, SpanFromAbove, 9}}, Frame -> All]Grid[{{1, SpanFromLeft, 3}, {SpanFromAbove, SpanFromBoth, 6}, {7, 8, 9}}, Frame -> All]並べ方 (2)
スタイリング (21)
背景色 (13)
Grid[Table[x, {4}, {7}], Background -> StandardBlue]Grid[Table[x, {4}, {7}], Background -> {{StandardBlue, StandardGray}, None}]Grid[Table[x, {4}, {7}], Background -> {None, {StandardBlue, StandardGray}}]Grid[Table[x, {4}, {7}], Background -> {None, {None, {StandardGray}}}]Grid[Table[x, {4}, {7}], Background -> {None, {StandardBlue, {None}, StandardBlue}}]Grid[Table[x, {6}, {7}], Background -> {None, {{StandardGray, None}}}]最初の行の背景を灰色にして,次から背景色なしと背景色青のパターンを繰り返す:
Grid[Table[x, {6}, {7}], Background -> {None, {StandardGray, {None, StandardBlue}}}]Grid[Table[x, {6}, {7}], Background -> {{{None}, StandardYellow}, None}]Grid[Table[x, {6}, {7}], Background -> {{{None}, StandardYellow}, {StandardGray, {None, StandardBlue}}}]Grid[Table[x, {6}, {7}], Background -> {{3 -> StandardYellow}, {StandardGray, {None, StandardBlue}}}]最初の2行の色を指定し,行のインデックスを使って追加の行を指定する:
Grid[Table[x, {7}, {7}], Background -> {None, {{StandardGray, StandardBlue}, {4 -> StandardPink, 5 -> StandardGreen}}}]行に繰り返しパターンを指定し,行のインデックスを使って例外を指定する:
Grid[Table[x, {7}, {7}], Background -> {None, {{{StandardGray, StandardBlue}}, {4 -> StandardPink, 5 -> StandardGreen}}}]Grid[Table[x, {4}, {7}], Background -> {{StandardBlue, {None}, StandardBlue}, None}]項目のスタイル (8)
Grid[Table[x, {4}, {7}], ItemStyle -> StandardRed]Grid[Table[x, {4}, {7}], ItemStyle -> {{StandardRed}, {}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{Bold}, {Bold}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{}, {Directive[{FontFamily -> "Times", Italic, StandardRed}]}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{}, {None, {StandardBlue}}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{}, {{StandardBlue, StandardRed}}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{}, {{Directive[StandardBlue, Bold], Directive[StandardRed, Italic]}}}]Grid[{{Item[1, Background -> StandardRed, Frame -> True], 2}, {3, 4}}]間隔 (4)
Grid[Array[Power, {5, 5}], Frame -> All, Alignment -> Right]Grid[Array[Power, {5, 5}], Frame -> All, Alignment -> Right, ItemSize -> All]Grid[Table[x, {3}, {3}], Frame -> All, Spacings -> 2]Grid[Table[x, {3}, {3}], Frame -> All, Spacings -> {2, 0}]オプション (36)
Alignment (2)
Grid[{{Graphics[Rectangle[], ImageSize -> 20], Graphics[Rectangle[], ImageSize -> 30]}, {Graphics[Rectangle[], ImageSize -> 40], Graphics[Rectangle[], ImageSize -> 50]}}, Alignment -> {{Right, Left}, {Bottom, Top}}]Grid[{{1.234, 12.34}, {123.4, 1234.}, {1234, 1.234}}, Alignment -> "."]AllowedDimensions (1)
Background (7)
Grid[Table[x, {4}, {7}], Background -> StandardPink]Grid[Table[x, {4}, {7}], Background -> {{StandardPink, StandardGray}, None}]Grid[Table[x, {4}, {7}], Background -> {{1 -> StandardPink, 2 -> StandardGray}, None}]Grid[Table[x, {4}, {7}], Background -> {None, {StandardPink, StandardGray}}]Grid[Table[x, {4}, {7}], Background -> {{{StandardPink, StandardGray}}, None}]Grid[Table[x, {4}, {7}], Background -> {{{{StandardPink, StandardGray}}, {1 -> StandardYellow, -1 -> StandardYellow}}, None}]Grid[Table[x, {4}, {7}], Background -> {{{StandardYellow, None}}, {{StandardPurple, None}}}]Grid[Table[x, {4}, {7}], Background -> {None, None, {{1, 1} -> StandardPink, {3, 3} -> StandardRed}}]Grid[Table[x, {4}, {7}], Background -> {None, None, {{{1, 3}, {2, 4}} -> StandardPink}}]BaselinePosition (3)
{x, y, Grid[{{a, b}, {c, d}}, Frame -> True], z}{x, y, Grid[{{a, b}, {c, d}}, BaselinePosition -> Bottom, Frame -> True], z}{x, y, Grid[{{b, c}, {d, e}}, BaselinePosition -> {{1, 2}, Bottom}, Frame -> True], z}{x, y, Grid[{{b ^ 2, g}, {d, e ^ 2}}, BaselinePosition -> {{1, 2}, Bottom}, Frame -> True], z}Dividers (3)
Grid[Table[x, {4}, {7}], Dividers -> Center]Grid[Table[x, {4}, {11}], Dividers -> {{{True, False}}, False}]Grid[Table[x, {4}, {11}], Dividers -> {{{{True, False}}, -1 -> True}, False}]Grid[Table[x, {4}, {7}], Dividers -> {{2 -> StandardRed, -2 -> StandardBlue}, {2 -> StandardRed, -2 -> StandardBlue}}]Frame (4)
Grid[Table[x, {4}, {7}], Frame -> True]Grid[Table[x, {4}, {7}], Frame -> All]Grid[Table[x, {4}, {7}], Frame -> {None, None, {{2, 1} -> True, {3, 5} -> True}}]Grid[Table[x, {4}, {7}], Frame -> {None, None, {{{1, 3}, {2, 4}} -> True}}]FrameStyle (3)
FrameStyleは,さまざまなグラフィックス指示子をサポートする:
Grid[{{x, x, x, x, x, x, x}, {x, x, x, x, x, x, x}, {x, x, x, x, x, x, x}, {x, x, x, x, x, x, x}}, Dividers -> {2 -> True, False}, Frame -> {{True}, False}, FrameStyle -> Directive[Dashing[2], Thickness[2], StandardBlue]]FrameStyleはDividersとItemを含む格子線のすべてのソースに適用される:
Grid[{{x, x, x, x, x, x, x}, {x, Item[x, Frame -> True], x, x, x, x, x}, {x, x, x, x, x, x, x}, {x, x, x, x, x, x, x}}, Dividers -> {False, 2 -> True}, Frame -> {1 -> True, False}, FrameStyle -> Directive[Dashing[2], Thickness[2], StandardBlue]]FrameStyleによって与えられる指示子は,他で指定されたものと組み合される:
Grid[{{x, x, x, x, x, x, x}, {x, Item[x, Frame -> StandardGreen], x, x, x, x, x}, {x, x, x, x, x, x, x}, {x, x, x, x, x, x, x}}, Dividers -> {2 -> StandardRed, 2 -> StandardRed}, Frame -> {1 -> True, False}, FrameStyle -> Directive[Dashing[2], Thickness[2], StandardBlue]]ItemSize (4)
Grid[{{30!, 35!}}, ItemSize -> 10, Frame -> True]ItemSize->Allとすると,すべての項目が同じ大きさになる:
Grid[{{10!, 20!}}, ItemSize -> All, Frame -> All]ItemSize->Automaticとすると,テキストはページ幅で改行される:
Grid[{{100!}, {50!}}, ItemSize -> Automatic, Frame -> All]Grid[{{100!}, {50!}}, ItemSize -> Full, Frame -> All]ItemStyle (5)
Grid[Table[x, {4}, {7}], ItemStyle -> StandardBlue]Directiveを使って複数のスタイル指示子を包み込む:
Grid[Table[x, {4}, {7}], ItemStyle -> Directive[FontSize -> 16, StandardRed]]Grid[Table[x, {4}, {7}], ItemStyle -> "Section"]Grid[Table[x, {4}, {7}], ItemStyle -> {Automatic, Automatic, {{1, 1} -> StandardRed, {3, 4} -> Underlined}}]Grid[Table[x, {4}, {7}], ItemStyle -> {Automatic, Automatic, {{{1, 3}, {2, 4}} -> StandardGreen}}]Spacings (4)
Grid[Table[x, {4}, {7}], Spacings -> {0, 0}]Grid[Table[x, {4}, {7}], Spacings -> {Automatic, 0}]Grid[Table[x, {4}, {7}], Spacings -> {4, 0.5}]Grid[Table[x, {3}, {7}], Spacings -> {{1, 4}, 0}, Frame -> All]Grid[Table[x, {3}, {7}], Spacings -> {{1, 2}, 0}, Frame -> All]アプリケーション (2)
Grid[{{Text["greeks"], SpanFromLeft}, {PasteButton[α], PasteButton[β]}, {PasteButton[γ], PasteButton[δ]}}, Frame -> True, Spacings -> {0, 0}]data = {{"first", 1, 2, 3}, {"second", 11, 5, 6}, {"third", 111, 8, 9}, {"fourth", 1111, 10, 11}};{header, stripe1, stripe2, light, dark} = LightDarkSwitched /@ {
LightOrange, White, LightBlue, GrayLevel[0.8], GrayLevel[0.2]};Text @ Grid[Prepend[data, {"name", "a", "b", "c"}], Background -> {None, {header, {stripe1, stripe2}}}, Dividers -> {{dark, {light}, dark}, {dark, dark, {False}, dark}}, Alignment -> {{Left, Right, {Left}}}, ItemSize -> {{10, 5, 3, 3}}, ItemStyle -> 14, Spacings -> {Automatic, .8}]特性と関係 (1)
考えられる問題 (2)
リストで与えられたスタイルは,連続する列または行に対応すると解釈される:
Grid[{{1, 2, 3, 4}, {5, 6, 7, 8}}, ItemStyle -> {{StandardRed, 18, Italic}, None}]Directiveは複数のスタイルを1つのグループにまとめる:
Grid[{{1, 2, 3, 4}, {5, 6, 7, 8}}, ItemStyle -> {Directive[StandardRed, 18, Italic], None}]行と列の両方について結合する際はSpanFromBothを適切に使う必要がある:
Grid[{{1, SpanFromLeft, 2}, {SpanFromAbove, SpanFromAbove, 3}, {4, 5, 6}}]Grid[{{1, SpanFromLeft, 2}, {SpanFromAbove, SpanFromBoth, 3}, {4, 5, 6}}]おもしろい例題 (3)
Grid[{ {"", Item[ "", Background -> Red], SpanFromLeft}, {"", SpanFromAbove, SpanFromBoth}, {Item["", Background -> Blue], "", ""}, {SpanFromAbove, SpanFromAbove, Item[ "", Background -> Yellow]} }, Dividers -> {{2 -> Thickness[3], 3 -> Thickness[3]}, {2 -> Thickness[5], 3 -> Thickness[3], 4 -> Thickness[3]}}, ItemSize -> {{1 -> 4, 2 -> 9, 3 -> 1}, {1 -> 6, 2 -> 6, 3 -> 2, 4 -> 2}}]Grid[Table[, {9}, {9}],
ItemSize -> {2, 2}, Dividers -> {{{Thickness[2], True, True}}, {{Thickness[2], True, True}}},
Background -> {Automatic, Automatic,
Flatten[Table[{i, j} -> If[EvenQ[Plus @@ Floor[{i - 1, j - 1} / 3]],
StandardGray, None], {i, 9}, {j, 9}]]}]Grid[Table[RandomChoice[{SpanFromLeft, SpanFromAbove, Item[RandomInteger[1000], Background -> LightDarkSwitched[Hue[RandomReal[], .2, .9]]]}], {20}, {12}], Frame -> All]テクニカルノート
-
▪
- 表と行列 ▪
- Grid,Row,Column ▪
- フォーマット出力
関連するガイド
-
▪
- 格子と表 ▪
- レイアウトと表 ▪
- ノートブックドキュメントの生成 ▪
- ユーザインターフェース構成とレイアウト ▪
- 構造化されたデータ集合の計算 ▪
- データの可視化 ▪
- 数学タイプセット ▪
- 自動化されたレポート ▪
- パレット ▪
- テキストの生成 ▪
- データの配列の操作 ▪
- フォームインターフェースとアプリの作成 ▪
- スタンドアロンインターフェース
関連するワークフロー
- テキストを含む格子を作る ▪
- 出力データの格子を作る ▪
- グラフィックスを格子に入れる ▪
- パレットを作成する
関連リンク
-

An Elementary Introduction to the Wolfram Language
: Arrays, or Lists of Lists
-

An Elementary Introduction to the Wolfram Language
: Pure Anonymous Functions
-

An Elementary Introduction to the Wolfram Language
: More about Pure Functions
-

An Elementary Introduction to the Wolfram Language
: Rearranging Lists
-

An Elementary Introduction to the Wolfram Language
: Layout and Display
テキスト
Wolfram Research (2007), Grid, Wolfram言語関数, https://reference.wolfram.com/language/ref/Grid.html (2012年に更新).
CMS
Wolfram Language. 2007. "Grid." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/Grid.html.
APA
Wolfram Language. (2007). Grid. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Grid.html
BibTeX
@misc{reference.wolfram_2026_grid, author="Wolfram Research", title="{Grid}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/Grid.html}", note=[Accessed: 07-July-2026]}
BibLaTeX
@online{reference.wolfram_2026_grid, organization={Wolfram Research}, title={Grid}, year={2012}, url={https://reference.wolfram.com/language/ref/Grid.html}, note=[Accessed: 07-July-2026]}