# 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.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]//TableForm= | |

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.

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]//FullForm= | |

In[6]:= |

Out[6]= |

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 |

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]//PaddedForm= | |

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]//PaddedForm= | |

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.

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

In[14]:= |

Out[14]= |

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.

In[15]:= |

Out[15]= |

In[16]:= |

Out[16]= |

In[17]:= |

Out[17]= |

In[18]:= |

Out[18]= |

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

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.

In[21]:= |

Out[21]= |

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 , 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.

In[22]:= |

Out[22]= |

In[23]:= |

Out[23]= |

In[24]:= |

Out[24]= |

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.

In[25]:= |

Out[25]= |

In[26]:= |

Out[26]= |

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.

In[27]:= |

Out[27]= |

In[28]:= |

Out[28]= |

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.

In[29]:= |

Out[29]= |

In[30]:= |

Out[30]= |

In[31]:= |

Out[31]= |

In[32]:= |

Out[32]= |

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.

In[33]:= |

Out[33]= |

In[34]:= |

Out[34]= |

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 setting in Item.

In[35]:= |

Out[35]= |

In[36]:= |

Out[36]= |

In[37]:= |

Out[37]= |

## 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[39]:= |

Out[39]//TableForm= | |

In[40]:= |

Out[40]//TableForm= | |

In[41]:= |

Out[41]//TableForm= | |

In general, when you print an -dimensional table, successive dimensions are alternately given as columns and rows. By setting the option TableDirections->{dir_{1}, dir_{2}, ...}, where the 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, ...}.

In[42]:= |

Out[42]//TableForm= | |

TableForm can handle arbitrary "ragged" arrays. It leaves blanks wherever there are no elements supplied.

In[43]:= |

Out[43]//TableForm= | |

In[44]:= |

Out[44]//TableForm= | |

You can control the number of levels in a nested list to which TableForm goes by setting the option TableDepth.

In[45]:= |

Out[45]//TableForm= | |

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.

In[46]:= |

Out[46]//TableForm= | |

In[47]:= |

Out[47]//TableForm= | |

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 specifies that successive objects should abut.

In[48]:= |

Out[48]//TableForm= | |

None | no labels in any dimension |

Automatic | successive integer labels in each dimension |

{{lbl_{11},lbl_{12},...},...} | explicit labels |

Settings for the option TableHeadings.

In[49]:= |

Out[49]//TableForm= | |

In[50]:= |

Out[50]//TableForm= | |

In[51]:= |

Out[51]//TableForm= | |