Grid[{{expr11,expr12,…},{expr21,expr22,…},…}]
一个将 exprij 放置于二维网格的对象.
Grid
Grid[{{expr11,expr12,…},{expr21,expr22,…},…}]
一个将 exprij 放置于二维网格的对象.
更多信息和选项
- 在笔记本中,您可以通过在二维结构中输入
来增加列数,用
增加行数. 在默认的情况下,这些结果可以对嵌套列表进行计算. 您可以使用 Grid[layout] 来保存 Grid. - 您可以在 Grid 中使用
移动至下一个占位符,使用
移出整个 Grid. - 在 StandardForm 和 TraditionalForm 中,Grid[…] 是一个网格.
- 在 InputForm 中, Grid[…] 按字面意思等于 Grid[…].
- Normal[grid] 用来提取一个列表的列来制作网格.
- exprij 可以是任意表达式,包括图形和控制.
- 您可以在 Grid 的串元素中输入文本.您也可以使用 Text["string"] 或 Style["string","style"] 指定特殊格式.
- 在 Grid[{list1,list2,…}] 中,listi 全部长度不需要一致;在网格最后的较短的行中将有空的间距.
- 您可以指定元素 e 在一个网格中横跨多个位置使用,例如,Grid[{{e,SpanFromLeft,SpanFromLeft},…}].
- 下列指定横跨的特殊位置:
-
SpanFromLeft 从左边横跨 SpanFromAbove 从上方横跨 SpanFromBoth 从左边和上方跨越 - 一个特殊元素可能跨越多行和多列,这种横跨按照 {{e,SpanFromLeft,SpanFromLeft,…}, {SpanFromAbove,SpanFromBoth,SpanFromBoth,…},…} 的长方形矩阵形式.
- 在笔记本中,您可在网格中使用 合并 菜单项,此合并使被选元素形成一个单独的跨越元素.
- 可给出以下选项:
-
Alignment {Center,Baseline} 水平项和垂直项的排列 AllowedDimensions Automatic 对行数或列数的限制 AutoDelete False 如果只有一个项保留,是否去除网格结构 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 
对于单个的 i,j 元素,指定明确规则 - speck 有下列形式:
-
{s1,s2,…,sn} 使用从 s1 到 sn;然后使用缺省 {{c}} 所用情况均使用 c {{c1,c2}} 交替使用 c1 和 c2 {{c1,c2,…}} 循环使用所有 ci {s,{c}} 使用 s,然后重复使用 c {s1,{c},sn} 使用 s1,然后重复使用 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 从第一项开始,最后一项结束.
- 在网格中使用 Item 的设置,例如 Alignment,Background 和 Frame,可有效指定各自项.
- 以 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[{{"first", "second"}, {"third", "fourth"}}]]范围 (43)
网格元素 (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)
格式 (22)
背景颜色 (13)
Grid[Table[x, {4}, {7}], Background -> LightBlue]Grid[Table[x, {4}, {7}], Background -> {{LightBlue, LightGray}, None}]Grid[Table[x, {4}, {7}], Background -> {None, {LightBlue, LightGray}}]Grid[Table[x, {4}, {7}], Background -> {None, {None, {LightGray}}}]Grid[Table[x, {4}, {7}], Background -> {None, {LightBlue, {None}, LightBlue}}]Grid[Table[x, {6}, {7}], Background -> {None, {{LightGray, None}}}]Grid[Table[x, {6}, {7}], Background -> {None, {LightGray, {None, LightBlue}}}]Grid[Table[x, {6}, {7}], Background -> {{{None}, Yellow}, None}]Grid[Table[x, {6}, {7}], Background -> {{{None}, Yellow}, {LightGray, {None, LightBlue}}}]Grid[Table[x, {6}, {7}], Background -> {{3 -> Yellow}, {LightGray, {None, LightBlue}}}]Grid[Table[x, {7}, {7}], Background -> {None, {{LightGray, LightBlue}, {4 -> LightPink, 5 -> LightGreen}}}]Grid[Table[x, {7}, {7}], Background -> {None, {{{LightGray, LightBlue}}, {4 -> LightPink, 5 -> LightGreen}}}]Grid[Table[x, {4}, {7}], Background -> {{LightBlue, {None}, LightBlue}, None}]项样式 (9)
Grid[Table[x, {4}, {7}], ItemStyle -> Red]Grid[Table[x, {4}, {7}], ItemStyle -> {{Red}, {}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{Bold}, {Bold}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{}, {Directive[{FontFamily -> "Times", Italic, Red}]}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{}, {None, {Blue}}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{}, {None, {Blue}}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{}, {{Blue, Red}}}]Grid[Table[x, {4}, {7}], ItemStyle -> {{}, {{Directive[Blue, Bold], Directive[Red, Italic]}}}]Grid[{{Item[1, Background -> Red, 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 -> Pink]Grid[Table[x, {4}, {7}], Background -> {{Pink, Gray}, None}]Grid[Table[x, {4}, {7}], Background -> {{1 -> Pink, 2 -> Gray}, None}]Grid[Table[x, {4}, {7}], Background -> {None, {Pink, Gray}}]Grid[Table[x, {4}, {7}], Background -> {{{Pink, Gray}}, None}]Grid[Table[x, {4}, {7}], Background -> {{{{Pink, Gray}}, {1 -> Yellow, -1 -> Yellow}}, None}]Grid[Table[x, {4}, {7}], Background -> {{{Yellow, None}}, {{Purple, None}}}]Grid[Table[x, {4}, {7}], Background -> {None, None, {{1, 1} -> Pink, {3, 3} -> Red}}]Grid[Table[x, {4}, {7}], Background -> {None, None, {{{1, 3}, {1, 3}} -> Pink}}]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 -> Red, -2 -> Blue}, {2 -> Red, -2 -> Blue}}]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}, {1, 3}} -> 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], Blue]]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], Blue]]FrameStyle 给出的指令同其它指令混合使用:
Grid[{{x, x, x, x, x, x, x}, {x, Item[x, Frame -> Green], x, x, x, x, x}, {x, x, x, x, x, x, x}, {x, x, x, x, x, x, x}}, Dividers -> {2 -> Red, 2 -> Red}, Frame -> {1 -> True, False}, FrameStyle -> Directive[Dashing[2], Thickness[2], Blue]]ItemSize (4)
Grid[{{30!, 35!}}, ItemSize -> 10, Frame -> True]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 -> Blue]使用 Directive 封装多个格式指令:
Grid[Table[x, {4}, {7}], ItemStyle -> Directive[FontSize -> 16, Red]]Grid[Table[x, {4}, {7}], ItemStyle -> "Section"]Grid[Table[x, {4}, {7}], ItemStyle -> {Automatic, Automatic, {{1, 1} -> Red, {3, 3} -> Underlined}}]Grid[Table[x, {4}, {7}], ItemStyle -> {Automatic, Automatic, {{{1, 3}, {1, 3}} -> Green}}]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}};Text@Grid[Prepend[data, {"name", "a", "b", "c"}], Background -> {None, {Lighter[Yellow, .9], {White, Lighter[Blend[{Blue, Green}], .8]}}}, Dividers -> {{Darker[Gray, .6], {Lighter[Gray, .5]}, Darker[Gray, .6]}, {Darker[Gray, .6], Darker[Gray, .6], {False}, Darker[Gray, .6]}}, Alignment -> {{Left, Right, {Left}}}, ItemSize -> {{10, 5, 3, 3}}, Frame -> Darker[Gray, .6], ItemStyle -> 14, Spacings -> {Automatic, .8}]属性和关系 (1)
可能存在的问题 (2)
Grid[{{1, 2, 3, 4}, {5, 6, 7, 8}}, ItemStyle -> {{Red, 18, Italic}, None}]Directive 使多种样式集合成一个单独的集体:
Grid[{{1, 2, 3, 4}, {5, 6, 7, 8}}, ItemStyle -> {Directive[Red, 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]],
Darker[White], White], {i, 9}, {j, 9}]]}]Grid[Table[RandomChoice[{SpanFromLeft, SpanFromAbove, Item[RandomInteger[1000], Background -> Hue[RandomReal[], .2, .9]]}], {20}, {12}], Frame -> All]相关的工作流程
- 制作含有文字的网格 ▪
- 以网格形式显示输出数据 ▪
- 把图形放到网格中 ▪
- 制作面板
文本
Wolfram Research (2007),Grid,Wolfram 语言函数,https://reference.wolfram.com/language/ref/Grid.html (更新于 2012 年).
CMS
Wolfram 语言. 2007. "Grid." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2012. https://reference.wolfram.com/language/ref/Grid.html.
APA
Wolfram 语言. (2007). Grid. Wolfram 语言与系统参考资料中心. 追溯自 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: 10-August-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: 10-August-2026]}