MATHEMATICA HOW TO

# How to | Put Headings in a Table

Mathematica provides great flexibility for displaying and styling headings in a table. You can use Prepend or ArrayFlatten to add headings to rows and columns and then use Grid with any of its styling elements to display them in a table.

Mathematica lets you control and customize the display of data in your table. Headings are just like any other element of a table.

Set up a table of values:

 Out[49]=

Prepend headings for columns:

 Out[50]=

Display the data, with column headings, using Grid:

 Out[51]=

Use MapThread to prepend headings for rows:

 Out[52]=

Display the data with headings for rows and columns, using Grid with Frame:

 Out[53]=

Set up a table of circles:

Use GraphicsGrid to display the circles in a grid:

 Out[55]=

Create and style column headings:

 Out[56]=

Prepend the styled column headings to the circles:

View the styled table with GraphicsGrid:

 Out[58]=

The following data represents yields for three types of soils and two types of corn seeds:

The data can be grouped by soil type by using First with GatherBy to gather the data by the first element of each data point:

 Out[85]=

To prepare the data for display in a table, use Flatten at level one, which here makes one list of triples. The symbol specifies the most recent output, which in this case is the grouped data:

 Out[61]=

The observation number within each soil type will serve as the corresponding row heading.

Use Length to count the number of observations within each soil type:

 Out[62]=

Use Range to generate a list of successive integers beginning with 1 and ending with the number of observations within each soil type:

 Out[63]=

Prepare the numbers for use as row headings by using Flatten to compress them into a single list:

 Out[64]=

Create column headings for the soil type, seed type, and yield data. You will create a column heading for the observation number in the next step, so you do not need to do so here:

Use ArrayFlatten to add the observation numbers, along with the column heading , to the data:

 Out[87]=

Use Grid to display the data in a table:

 Out[88]=

Use some of the options available in Grid to add styling to the table:

 Out[89]=

For more examples of table formatting and styling, see "How to: Format a Table of Data", and "Grids, Rows, and Columns".

You can also create tables and add headings to them using TableForm.

Define a set of data to work with:

Create the row and column headings for your data:

Create a table with TableForm, and use the TableHeadings option to add your headings:

 Out[3]//TableForm=

While TableForm allows you to create tables, it does not support the extensive styling options that are available to Grid.