22. Creating custom tables

You can add simple to complex tables to a LaTeX document using several types of packages, depending on the requirements of the table.

## Inserting table packages

LaTeX provides several packages for adding tables to a LaTeX document. Two useful packages for tables are the tabular and the supertabular package.

Note: When using tabular or supertabular, the cell contents are in text mode.

## Defining a table using the tabular package

Using the tabular package you can, for example, define a basic table with a header, three columns and rows as follows:

This explains what is happening in this definition:

• The line \begin{tabular}{|l|l|l|} creates a table with three columns that are left aligned and have a vertical line between each column.

• Next, column headings are added where each heading is marked off by a & symbol and where the row is ended with the command \\.

• A horizontal line is added using \hline.

## Definig a more complex table using supertabular

Using supertabular you can create more complex tables by adding the following commands to the stylesheet:

Then you can create a table as shown in the following example:

This explains what is happening in this definition:

• The environment command \begin{flushleft}places the table left aligned to the margin.

• The command \tablehead{} adds a table heading. In this case, it is empty so no table heading is used.

## Adding spacing to table cells

You can add spacing above and below the text in table row as follows:

Here is an example of it used in a table.

Click to continue.