Tables and Matrices
Column[list] | typeset as a column of elements |
Grid[list] | typeset as a grid of elements |
TableForm[list] | print in tabular form |
Formatting lists as tables and matrices.
Grid and Column are wrappers which do not evaluate, but typeset their contents into appropriate forms. They are typesetting constructs and require a front end to render correctly.
PaddedForm[Column[list],tot] | print a column with all numbers padded to have room for tot digits |
PaddedForm[Grid[list],tot] | print a table with all numbers padded to have room for tot digits |
PaddedForm[Grid[list],{tot,frac}] | put frac digits to the right of the decimal point in all approximate real numbers |
SpanFromLeft | span from the element on the left |
SpanFromAbove | span from the element above |
SpanFromBoth | span from the element above and to the left |
Symbols used to represent spanning in Grid.
Grid takes a rectangular matrix as its first argument. Individual elements of the Grid can span across multiple rows, columns, or a rectangular subgrid by specifying the areas to be spanned. The spanning element is always specified in the upper left-hand corner of the spanning area, and the remaining area is filled in with the appropriate spanning symbols.
option | default value | |
Background | None | what background colors to use |
BaselinePosition | Automatic | what to align with a surrounding text baseline |
BaseStyle | {} | base style specifications for the grid |
Frame | None | where to draw frames in the grid |
FrameStyle | Automatic | style to use for frames |
Some options which affect the behavior of a Grid as a whole.
Column is a shorthand for specifying a Grid with one column. Since the two functions are similar, the same options can be used for each one.
option | default value | |
Alignment | {Center,Baseline} | horizontal and vertical alignment of items |
Dividers | None | where to draw divider lines in the grid |
ItemSize | Automatic | width and height of each item |
ItemStyle | None | styles for columns and rows |
Spacings | {0.8,0.1} | horizontal and vertical spacings |
Some options which affect the columns and rows of a Grid.
The options for Grid which affect individual rows and columns all share a similar syntax. The options can be specified as {x,y} , where x applies to all of the columns and y applies to all of the rows; x and y can be single values, or they can be a list of values which represent each column or row in turn.
When Background or ItemStyle options specify distinct settings for rows and columns, the front end will attempt to combine the settings where the rows and columns overlap.
To repeat an individual row or column specification over multiple rows or columns, wrap it in a list. The repeated element will be used as often as necessary. If you wrap multiple elements in a list, the entire list will be repeated in sequence.
The ItemSize and Spacings options take their horizontal measurements in ems and their vertical measurements in line heights based upon the current font. Both options also can take a Scaled coordinate, where the coordinate specifies the fraction of the total cell width or window height. The ItemSize option also allows you to request as much space as is required to fit all of the elements in the given row or column by using the keyword Full.
option | default value | |
Alignment | {Center,Baseline} | horizontal and vertical alignment of items |
Background | None | what background colors to use |
BaseStyle | {} | base style specifications for the item |
Frame | None | where to draw frames around the item |
FrameStyle | Automatic | style to use for frames |
ItemSize | Automatic | width and height of each item |
Some options for Item.
Many of the settings which can be applied to entire rows and columns can also be applied individually to the elements of a Grid or Column by using the Item wrapper. Item allows you to change these settings at the granularity of a single item. Settings which are specified at the Item level always override settings from the Grid or Column as a whole.
Most of the options to Item take the same settings as their Grid counterparts. However, the Alignment and ItemSize options, which allow complex row and column settings in Grid, take only the {horizontal,vertical} setting in Item.
Formatting Higher-Dimensional Data
Column supports one-dimensional data, and Grid supports two-dimensional data. To print arrays with an arbitrary number of dimensions, you can use TableForm.
In general, when you print an ‐dimensional table, successive dimensions are alternately given as columns and rows. By setting the option TableDirections->{dir1,dir2,…}, where the diri are Column or Row, you can specify explicitly which way each dimension should be given. By default, the option is effectively set to {Column,Row,Column,Row,…}.
TableForm can handle arbitrary "ragged" arrays. It leaves blanks wherever there are no elements supplied.
You can control the number of levels in a nested list to which TableForm goes by setting the option TableDepth.
option name | default value | |
TableDepth | Infinity | maximum number of levels to include in the table |
TableDirections | {Column,Row,Column,…} | whether to arrange dimensions as rows or columns |
TableAlignments | {Left,Bottom,Left,…} | how to align the entries in each dimension |
TableSpacing | {1,3,0,1,0,…} | how many spaces to put between entries in each dimension |
TableHeadings | {None,None,…} | how to label the entries in each dimension |
Options for TableForm.
With the option TableAlignments, you can specify how each entry in the table should be aligned with its row or column. For columns, you can specify Left, Center, or Right. For rows, you can specify Bottom, Center, or Top. If you set TableAlignments->Center, all entries will be centered both horizontally and vertically. TableAlignments->Automatic uses the default choice of alignments.
You can use the option TableSpacing to specify how much horizontal space there should be between successive columns, or how much vertical space there should be between successive rows. A setting of 0 specifies that successive objects should abut.
None | no labels in any dimension |
Automatic | successive integer labels in each dimension |
{{lbl11,lbl12,…},…} | explicit labels |
Settings for the option TableHeadings.