LaTeX Typesetting – Tables

January 2nd, 2011

One area of LaTeX that is not always straightforward is producing tabular material. In this post we will look at some of the basics of creating tables in a LaTeX document.


Fast Tube by Casper

When creating tables there is a tabular environment that can be used and we need to specify the number of columns using characters to indicate the text alignment in each column. A simple three column table where all columns are centred would be produced like this:

\begin{tabular}{ccc}
...
\end{tabular}

On individual lines of data the ampersand character is used to indicate different columns. So if we wanted to add a heading to the table we might add the following line within the tabular environment:

Name & Description & Frequency \\

The end of the line is indicated by the \\ and we can move on to the next row of the table on the following line.

We can add vertical lines between the columns by adding information to the column alignment specification. For example to add these vertical lines between all three columns we would write:

\begin{tabular}{|c|c|c|}
...
\end{tabular}

Horizontal lines to cover the whole row can be added at the end of each line to get LaTeX to draw them underneath the most recent row of the table.

Name & Description & Frequency \\ \hline

This draws a line under the title row of our table.

An example of a complete table is given below using data from the International Monetary Fund for the GDP in 2009 for the top ten nations.

\begin{tabular}{|l|c|} \hline
Country & GDP (USD millions) \\ \hline
United States & 14,119,050 \\
Japan & 5,068,894 \\
People's Republic of China & 4,984,731 \\
Germany & 3,338,675 \\
France & 2,656,378 \\
United Kingdom & 2,178,856 \\
Italy & 2,118,264 \\
Brazil & 1,574,039 \\
Spain & 1,467,889 \\
Canada & 1,336,427 \\ \hline
\end{tabular}

Other useful resources are provided on the Supplementary Material page.

4 responses to “LaTeX Typesetting – Tables”

  1. Dave says:

    Whenever I’m trying to do a fancy table, I always check this outstanding tutorial:

    http://www.tug.org/pracjourn/2007-1/mori/mori.pdf
    Tables in LATEX2e: Packages and Methods, Lapo Filippo Mori

  2. cjr says:

    Don’t use \hline, it’s hideous within the tabular environment. Instead use the booktabs package, which provides the tools for publication-quality tables. Also, avoid vertical rules in tables wherever possible; again, see the booktabs package, which provides a good discussion of how to properly layout tables.

  3. tet says:

    I have never understood what was wrong with Knuth’s original plain TeX \halign environment.
    OK it’s a bit hard to do vertical rules but then you probably don’t really want them anyway.
    For everything else it’s just as easy to use as LaTeX tabular. In fact it’s better because it is so well documented in the TeX book. And yes you can use it mixed in with regular LaTeX.

  4. Ariv says:

    I am using Excel2Latex, a freeware, to transform a table in Excel to Latex. It works fine