LaTeX Typesetting – Tables

January 2, 2011
By

(This article was first published on Software for Exploratory Data Analysis and Statistical Modelling, and kindly contributed to R-bloggers)

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

To leave a comment for the author, please follow the link and comment on his blog: Software for Exploratory Data Analysis and Statistical Modelling.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , ,

Comments are closed.