Skip to Main Content
The University of Massachusetts Amherst

LaTeX

Getting Started with Tables

To begin creating tables, you will first need to load the package array (\usepackage{array}).

You will then create a tabular environment (\begin{tabular}...\end{tabular}).

Setting Up Your Table

First, as part of the opening to your tabular environment, you will create what is a called a "table preamble." This is to set the number of columns in your table, as well as the alignment of the contents of each column. To create your table preamble, open up a second mandatory argument (using another pair of braces). You will then enter "preamble tokens" into this argument to set the alignment. You will enter as many tokens as you want columns in the table. Options for tokens/alignment are:

  • lleft aligned
  • ccentered
  • r - right aligned
  • p{width} - fixed width columns with line wrapped/fully justified text

For example, if we wanted to create a table with four columns, where the first column is right justified, and the remaining three are centered, we would begin our table environment using the following command:

\begin{tabular}{rccc}

Adding Content to Your Table

Inside of the environment, begin by typing what you would like to appear in the first row of the first column. To move to the next column, type a & after the end of the first cell's contents. When you have reached the end of the row, type \\ to end the row and begin a new row beneath it. Below is an example of source code and its resulting output.

Adding Lines to Your Table

Adding Vertical Lines

To add vertical lines between columns in your table, simply add a | between the preamble tokens representing the columns you want separated. 


Adding Horizontal Lines

To add horizontal lines, you will need to use the booktabs package (\usepackage{booktabs}). Once you have loaded the booktabs package, you will have the following commands available:

  • \toprule - add a line at the top of your table
  • \midrule - add a line in the middle of your table (add it between the rows you want separated)
  • \bottomrule - add a line at the bottom of your table

Below is an example of the same source code and output from before, modified to add lines: