Grid
✖
Grid
is an object that formats with the exprij arranged in a two-dimensional grid.
Details and Options
- In a notebook, you can enter expressions in a two-dimensional layout by using to add columns and to add rows. By default, this layout evaluates to a nested list. You can make a Grid that preserves the layout by using Grid[layout].
- You can use to move to the next placeholder in a Grid. moves out of the whole Grid.
- Grid[…] formats as a grid in StandardForm and TraditionalForm.
- In InputForm, Grid[…] formats literally as Grid[…].
- Normal[grid] extracts the list of lists that make up a grid.
- The exprij can be expressions of any kind, including graphics and controls.
- You can enter text in an element of a Grid by giving it as a string. You can use Text["string"] or Style["string","style"] to specify a particular style.
- The listi in Grid[{list1,list2,…}] do not all need to be the same length; there will be empty space in the grid at the ends of shorter rows.
- You can specify that an element e should span multiple positions in a grid using, for example, Grid[{{e,SpanFromLeft,SpanFromLeft},…}].
- The following specify that a particular position should be spanned:
-
SpanFromLeft span from left SpanFromAbove span from above SpanFromBoth span from both left and above - A particular element can span both multiple rows and multiple columns, by having a rectangular section of the array with the form {{e,SpanFromLeft,SpanFromLeft,…}, {SpanFromAbove,SpanFromBoth,SpanFromBoth,…},…}.
- In a notebook, you can combine selected elements in a grid to make a single spanning element using the Make Spanning menu item.
- The following options can be given:
-
Alignment {Center,Baseline} horizontal and vertical alignment of items AllowedDimensions Automatic restrictions on number of rows or columns AutoDelete False whether to remove the grid structure if only one item remains Background None what background colors to use BaselinePosition Automatic what to align with a surrounding text baseline BaseStyle {} base style specifications for the grid DefaultElement "" what element to insert in an empty item Dividers {} where to draw divider lines in the grid Frame None where to draw frames in the grid FrameStyle Automatic style to use for frames ItemSize Automatic width and height of each item ItemStyle None styles for columns and rows Spacings Automatic horizontal and vertical spacings - Common settings for Frame include:
-
None no frame True frame around the whole grid All frame around every item in the grid {All, False} put a frame at every horizontal position (column lines) {False, All} put a frame at every vertical position (row lines) - Settings for the options Alignment, Background, Frame, ItemSize, and ItemStyle can be given as follows to apply separately to different items:
-
spec apply spec to all items {specx} apply specx at successive horizontal positions {specx,specy} apply speck at successive horizontal and vertical positions {specx,specy,rules} also allow explicit rules for individual i,j elements - The speck can have the following forms:
-
{s1,s2,…,sn} use s1 through sn, then use defaults {{c}} use c in all cases {{c1,c2}} alternate between c1 and c2 {{c1,c2,…}} cycle through all ci {s,{c}} use s, then repeatedly use c {s1,{c},sn} use s1, then repeatedly use c, but use sn at the end {s1,s2,…,{c1,c2,…},sm,…,sn} use the first sequence of si at the beginning, then cyclically use the ci, then use the last sequence of si at the end {s1,s2,…,{},sm,…,sn} use the first sequence of si at the beginning and the last sequence at the end {i1->v1,i2->v2,…} specify what to use at positions ik {spec,rules} use rules to override specifications in spec - With settings of the form {s1,s2,…,{…},sm,…,sn}, if there are more si specified than items across the grid, si from the beginning are used for the first items, and ones from the end are used for the last items.
- Settings such as Alignment, Background, and Frame can effectively be specified for individual items in the grid using Item.
- With the default setting ItemSize->Automatic, Grid will break elements across multiple lines if necessary.
- Grid will not change the size of graphics or other objects that have explicit ImageSize settings.
- For a grid with n items in a particular direction, Dividers and Spacings can specify settings for the n+1 gaps between elements, starting before the first element and ending after the last element.
- Settings for Dividers and Spacings can have the following forms:
-
spec apply spec to all gaps between items {specx,specy} apply specx, specy to successive horizontal and vertical gaps - The speci can have the same forms as for Alignment, Background, and other item-oriented options.
- The following settings can be used for BaselinePosition:
-
Axis axis of the middle row in the grid Baseline baseline of the middle row in the grid Bottom bottom of the whole grid Center halfway from top to bottom Top top of the whole grid {{i,j},pos} position pos in element i,j pos->ref baseline offset to make pos be aligned with ref - The BaselinePosition is by default taken to be Center->Axis.
- The settings for BaseStyle are appended to the default style typically given by the "Grid" style in the current stylesheet.
Examples
open allclose allBasic Examples (3)Summary of the most common use cases
https://wolfram.com/xid/0bufgq-dq0efw
Put a frame around every element:
https://wolfram.com/xid/0bufgq-d6xett
Use Text to format grid elements as text:
https://wolfram.com/xid/0bufgq-kmfxli
Scope (43)Survey of the scope of standard use cases
Elements in Grids (5)
Grid can contain elements of any size:
https://wolfram.com/xid/0bufgq-dkfemt
Grid can contain graphics or any other expressions:
https://wolfram.com/xid/0bufgq-fkwsdv
Grid can contain active controls:
https://wolfram.com/xid/0bufgq-epwr7
Create a grid with a single row:
https://wolfram.com/xid/0bufgq-k5xtk
https://wolfram.com/xid/0bufgq-4at1
Grid can be used to format grids with no rows, empty rows, or ragged rows:
https://wolfram.com/xid/0bufgq-56wh47
Frames and Grid Lines (5)
Put a frame around the whole grid:
https://wolfram.com/xid/0bufgq-bbpa2o
Put a frame around every element:
https://wolfram.com/xid/0bufgq-gsc84x
https://wolfram.com/xid/0bufgq-2mnjal
Put a frame around the first row and column:
https://wolfram.com/xid/0bufgq-cbpht5
Draw different frames with different styles:
https://wolfram.com/xid/0bufgq-ud2x0h
Put dividers at all horizontal positions:
https://wolfram.com/xid/0bufgq-mo15iw
Put dividers at all vertical positions:
https://wolfram.com/xid/0bufgq-e7ls8
Put dividers at the third horizontal and second vertical positions:
https://wolfram.com/xid/0bufgq-k67otn
Spanning Elements (3)
Make the element 4 span the column to its right:
https://wolfram.com/xid/0bufgq-f1j5kh
https://wolfram.com/xid/0bufgq-bigdgf
Make the element 2 span the row below it:
https://wolfram.com/xid/0bufgq-bjilaz
https://wolfram.com/xid/0bufgq-j9ntkl
https://wolfram.com/xid/0bufgq-n5900p
Alignment (2)
Styling (22)
Background Colors (13)
Draw the grid with a light blue background:
https://wolfram.com/xid/0bufgq-lqbfpn
Make the first columns light blue and gray:
https://wolfram.com/xid/0bufgq-bnroag
Make the first rows light blue and gray:
https://wolfram.com/xid/0bufgq-bqjon2
Make all rows except the first one gray:
https://wolfram.com/xid/0bufgq-fhuswn
Make the first and last rows light blue:
https://wolfram.com/xid/0bufgq-npfw6y
Use a repeating pattern for rows:
https://wolfram.com/xid/0bufgq-tzw0n
Make the first row gray, then a repeating pattern of none and light blue:
https://wolfram.com/xid/0bufgq-cmpl26
https://wolfram.com/xid/0bufgq-iqfk6g
Combine a final column highlight with a repeating row pattern:
https://wolfram.com/xid/0bufgq-i3j3xo
Highlight a specific column using its column index:
https://wolfram.com/xid/0bufgq-i6wron
Specify colors for the first two rows, and then additional rows using a column index:
https://wolfram.com/xid/0bufgq-bomewe
Specify rows as a repeating pattern with an exception specified with its row index:
https://wolfram.com/xid/0bufgq-dnis86
Make the first column and last column light blue:
https://wolfram.com/xid/0bufgq-bjvzdq
Item Styles (9)
Set the font color of the individual items to be red:
https://wolfram.com/xid/0bufgq-v104qp
Specify a style for the first column:
https://wolfram.com/xid/0bufgq-mejzwt
Specify a style for the first row and column:
https://wolfram.com/xid/0bufgq-dghgjq
Specify a complex style for the first row:
https://wolfram.com/xid/0bufgq-7ptvo
Set all item contents to be blue, except for the first row:
https://wolfram.com/xid/0bufgq-e60dal
Set all item contents to be blue, except for the first row:
https://wolfram.com/xid/0bufgq-mru24d
https://wolfram.com/xid/0bufgq-geise8
Alternate complex styles by row:
https://wolfram.com/xid/0bufgq-jns4iu
Embed styling options with a particular grid item:
https://wolfram.com/xid/0bufgq-ku8z1q
Spacing (4)
Make each row and column just big enough to fit the items they contain:
https://wolfram.com/xid/0bufgq-cwucbg
Leave the same amount of space for all items:
https://wolfram.com/xid/0bufgq-c0e4l
Set the horizontal spacing between items:
https://wolfram.com/xid/0bufgq-8dm3c
Set the horizontal and vertical spacings:
https://wolfram.com/xid/0bufgq-hc29nd
Options (36)Common values & functionality for each option
Alignment (2)
AllowedDimensions (1)
Background (7)
Draw the grid with a pink background:
https://wolfram.com/xid/0bufgq-l5rbwg
Pink and gray backgrounds for the columns at the first and second horizontal positions:
https://wolfram.com/xid/0bufgq-4y5go5
https://wolfram.com/xid/0bufgq-zqd9oa
Pink and gray backgrounds for the rows at the first and second vertical positions:
https://wolfram.com/xid/0bufgq-jgne6m
Alternating pink and gray backgrounds:
https://wolfram.com/xid/0bufgq-57g14a
Alternating backgrounds with yellow superimposed in the first and last positions:
https://wolfram.com/xid/0bufgq-hpart3
https://wolfram.com/xid/0bufgq-iz40di
Set the background for specific items:
https://wolfram.com/xid/0bufgq-xouktx
Set the background for a subregion of the grid:
https://wolfram.com/xid/0bufgq-hrrawi
BaselinePosition (3)
Align the center of the grid with the baseline of surrounding text:
https://wolfram.com/xid/0bufgq-so18k
Align the bottom of the grid with the baseline:
https://wolfram.com/xid/0bufgq-ouy59i
Align a specific grid element with the baseline:
https://wolfram.com/xid/0bufgq-cvwtao
https://wolfram.com/xid/0bufgq-mu61zq
Dividers (3)
https://wolfram.com/xid/0bufgq-6dliw4
Draw a divider at every other horizontal position:
https://wolfram.com/xid/0bufgq-5n8j6d
https://wolfram.com/xid/0bufgq-jl9abx
Draw dividers with specified styles:
https://wolfram.com/xid/0bufgq-4k3o0y
Frame (4)
FrameStyle (3)
FrameStyle supports a variety of graphics directives:
https://wolfram.com/xid/0bufgq-7jhzp1
FrameStyle is applied to all sources of grid lines, including Dividers and Item:
https://wolfram.com/xid/0bufgq-fcx7w4
Directives given with FrameStyle are combined with those specified elsewhere:
https://wolfram.com/xid/0bufgq-679ofv
ItemSize (4)
Make each item a fixed number of character-widths wide:
https://wolfram.com/xid/0bufgq-wjgp5y
ItemSize->All makes all items the same size:
https://wolfram.com/xid/0bufgq-6b3p1x
ItemSize->Automatic line-wraps textual items at the page width:
https://wolfram.com/xid/0bufgq-jqh95g
https://wolfram.com/xid/0bufgq-svsmhb
ItemStyle (5)
Set one overall style for grid items:
https://wolfram.com/xid/0bufgq-ky6nr6
Use Directive to wrap multiple style directives:
https://wolfram.com/xid/0bufgq-0k830b
Use a style from the current stylesheet:
https://wolfram.com/xid/0bufgq-ii1tld
https://wolfram.com/xid/0bufgq-la6zbv
https://wolfram.com/xid/0bufgq-8z00yq
Spacings (4)
Insert no additional space between rows or columns:
https://wolfram.com/xid/0bufgq-r4plfj
Insert no additional space between rows:
https://wolfram.com/xid/0bufgq-by065i
Specify spacing with numeric values:
https://wolfram.com/xid/0bufgq-fdf2p5
Use different spacings at the first vertical divider:
https://wolfram.com/xid/0bufgq-b3clze
https://wolfram.com/xid/0bufgq-hwqhmt
Applications (2)Sample problems that can be solved with this function
Properties & Relations (1)Properties of the function, and connections to other functions
Possible Issues (2)Common pitfalls and unexpected behavior
Styles given in a list will be interpreted as corresponding to successive columns or rows:
https://wolfram.com/xid/0bufgq-fn4hol
Directive groups styles into a single collective unit:
https://wolfram.com/xid/0bufgq-o49y91
To span across both rows and columns requires appropriate use of SpanFromBoth:
https://wolfram.com/xid/0bufgq-7kfcna
https://wolfram.com/xid/0bufgq-8z5anv
Neat Examples (3)Surprising or curious use cases
Wolfram Research (2007), Grid, Wolfram Language function, https://reference.wolfram.com/language/ref/Grid.html (updated 2012).
Text
Wolfram Research (2007), Grid, Wolfram Language function, https://reference.wolfram.com/language/ref/Grid.html (updated 2012).
Wolfram Research (2007), Grid, Wolfram Language function, https://reference.wolfram.com/language/ref/Grid.html (updated 2012).
CMS
Wolfram Language. 2007. "Grid." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/Grid.html.
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
Wolfram Language. (2007). Grid. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Grid.html
BibTeX
@misc{reference.wolfram_2024_grid, author="Wolfram Research", title="{Grid}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/Grid.html}", note=[Accessed: 09-January-2025
]}
BibLaTeX
@online{reference.wolfram_2024_grid, organization={Wolfram Research}, title={Grid}, year={2012}, url={https://reference.wolfram.com/language/ref/Grid.html}, note=[Accessed: 09-January-2025
]}