是一个用于指定所用背景色的选项.
Background
是一个用于指定所用背景色的选项.
更多信息
- Background 可以设定为任意颜色或不透明度.
- Background 是 Graphics、Plot、Text、Panel、Button 和 Cell 等函数的选项.
- 若是一个对象具有选项 Background->color,则所指定的颜色通常将被作为该对象所定义的整个区域的背景色.
- Style[expr,Background->color] 指定 color 仅作为 expr 边界框定义区域的背景色.
- 在诸如 Grid 的结构中,Item 用以指定填充一个特殊项完整区域的背景.
- 在顶层单元中,背景仅用于单元框架内的区域. 如果单元的背景颜色与其周围环境不匹配,即使没有绘制单元框架,单元也会包含单元框架边距. 显示为内联、附加等格式的单元不会受到类似影响. »
- Background->None 指定无背景,这样的背景效果是透明的.
- Background->Automatic 指定的背景和特殊对象的系统外部表征或窗口所用的一致. 对于 Inset 来说,Background->Automatic 意指将图形中的背景去除.
- 对于 Grid、Column 和 Row 对象,可将 Background 设置为一个列表,该列表能对个别的列、行或元素指定背景.
- 在 Dataset 中,Background 的设置可以是返回一组颜色的纯函数 f. 设置由 f[item,position,data] 给出,其中 data 是数据集的第一个参数.
范例
打开所有单元 关闭所有单元基本范例 (2)
范围 (4)
Grid[Table[x, {4}, {7}], Background -> Pink]Table[ExpressionCell["abc", Background -> col], {col, {RGBColor[1, 1, 0], Hue[.5, .3, .1], GrayLevel[.5], LABColor[1, .4, .8], XYZColor[.6, .9, .2]}}]LightDarkSwitched 可用于指定浅色和深色模式下的不同颜色:
Graphics[Disk[], Background -> LightDarkSwitched[LightGreen, Purple]]Grid[{{Item[a, Background -> Brown], b}, {c, d}}]推广和延伸 (5)
Grid[Table[x, {4}, {7}], Background -> {{Orange, Magenta}, None}]Grid[Table[x, {4}, {7}], Background -> {{Orange, {}, Magenta}, None}]Grid[Table[x, {4}, {7}], Background -> {None, {Orange, Magenta}}]Grid[Table[x, {4}, {7}], Background -> {{{Brown, Gray}}, None}]Grid[Table[x, {4}, {7}], Background -> {{{{Brown, Gray}}, {1 -> Pink, -1 -> Pink}}, None}]Grid[Table[x, {4}, {7}], Background -> {None, None, {{{1, 3}, {2, 4}} -> Pink}}]在 Dataset 中根据数值设置背景的颜色:
Dataset[Take[...], Background -> {"age" -> (If[# > 9, Pink, Automatic]&)}]应用 (3)
Grid[Table[Binomial[n, k], {n, 15}, {k, 15}], Background -> {None, {{Brown, Gray}}}]突出显示 Dataset 每一列的最大值:
Dataset[Table[RandomReal[], {5}, {3}], Background -> (If[# === Max[#3[[All, #2[[2]]]]], Orange, Automatic]&)]Dataset[Table[x y / 25., {x, 5}, {y, 5}], Background -> (LightDarkSwitched[Hue[1, #]]&)]属性和关系 (2)
{Graphics[{Opacity[0.5], Red, Disk[]}],
Graphics[{Opacity[0.5], Red, Disk[]}, Background -> Yellow]}使用 CellFrameMargins 绘制具有对比背景色且没有单元框架的单元:
CellPrint[ExpressionCell["abc", "Print", CellFrameMargins -> 20, Background -> Gray]]与环境匹配的背景色仅当存在单元框架时才使用 CellFrameMargins:
CellPrint[ExpressionCell["abc", "Print", CellFrameMargins -> 20, Background -> ThemeColor["Background"]]]CellPrint[ExpressionCell["abc", "Print", CellFrameMargins -> 20, Background -> ThemeColor["Background"], CellFrame -> True]]BackgroundNone 被视为匹配的背景色:
CellPrint[ExpressionCell["abc", "Print", CellFrameMargins -> 20, Background -> None]]CellFrameMargins 不适用于显示为内联、附加、浮动等格式的单元:
Row[{1, ExpressionCell[2, Background -> Gray], 3}]可能存在的问题 (1)
某些背景色在浅色模式下与默认字体颜色对比良好,但在深色模式下效果不佳:
ExpressionCell["light mode contrast", Background -> Yellow]这些问题可以通过将颜色封装在 LightDarkSwitched 中解决:
ExpressionCell["light mode contrast", Background -> LightDarkSwitched[Yellow]]ExpressionCell["light mode contrast", Background -> Purple]使用 LightDarkSwitched 并将 Automatic 作为第一个参数即可解决这些问题:
ExpressionCell["light mode contrast", Background -> LightDarkSwitched[Automatic, Purple]]巧妙范例 (1)
ContourPlot3D[x ^ 4 + y ^ 4 + z ^ 4 - (x ^ 2 + y ^ 2 + z ^ 2) == -1 / 2, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, Mesh -> 15, MeshFunctions -> {#1^2 + #2^2 + #3^2&}, MeshShading -> {None, Directive[Blue, Specularity[White, 50]], None, Directive[Yellow, Specularity[White, 50]]}, PlotPoints -> 35, MeshStyle -> Opacity[.3], Axes -> False, Boxed -> False, Background -> Black]相关链接
历史
1991年引入 (2.0) | 在以下年份被更新:1996 (3.0) ▪ 2007 (6.0) ▪ 2012 (9.0) ▪ 2020 (12.1)
文本
Wolfram Research (1991),Background,Wolfram 语言函数,https://reference.wolfram.com/language/ref/Background.html (更新于 2020 年).
CMS
Wolfram 语言. 1991. "Background." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2020. https://reference.wolfram.com/language/ref/Background.html.
APA
Wolfram 语言. (1991). Background. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/Background.html 年
BibTeX
@misc{reference.wolfram_2026_background, author="Wolfram Research", title="{Background}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/Background.html}", note=[Accessed: 12-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_background, organization={Wolfram Research}, title={Background}, year={2020}, url={https://reference.wolfram.com/language/ref/Background.html}, note=[Accessed: 12-August-2026]}