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:

1
2
3
4
5
6
7
8
9
\begin{center}
\begin{tabular}{|l|l|l|}
Column Heading & Column Heading & Column Heading \\\
\hline
Cell contents & Cell contents & Cell contents \\
Cell contents & Cell contents & Cell contents \\
Cell contents & Cell contents & Cell contents \\
\end{tabular}
\end{center}

This explains what is happening in this definition:

The cell contents follow the same structure as column headings.

Definig a more complex table using supertabular

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

1
2
3
4
5
6
\usepackage{supertabular}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{longtable}
\usepackage{tabulary}
\usepackage{colortbl}

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

1
2
3
4
5
6
7
8
9
10
11
\begin{flushleft}
\tablehead{}
\begin{supertabular}{|m{2cm}|m{6cm}|}
\hline
Heading 1 & Heading 2\\\hline
1st column and 1st row & 2nd column and 1st Row\\\hline
1st column and 2nd row & 2nd column and 2nd Row\\\hline
1st column and 3rd row & 2nd column and 3rd Row\\\hline
1st column and 4th row & 2nd column and 4th Row\\\hline
\end{supertabular}
\end{flushleft}

This explains what is happening in this definition:

Adding spacing to table cells

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

1
\setlength{\extrarowheight}{4pt}

Here is an example of it used in a table.

1
2
3
4
5
6
7
8
9
10
11
12
13
\begin{footnotesize}
\setlength{\extrarowheight}{7.6pt}
\begin{tabular}{l|m{7cm}}
\hline
\hline
Cell contents & Cell contents  \\\hline
\hline
Cell contents & Cell contents  \\\hline
Cell contents & Cell contents  \\\hline
Cell contents & Cell contents  \\\hline
\hline
\end{tabular}
\end{footnotesize}

Click to continue.