About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Smile for the Camera: a new cybercrime short story ebook.


4.6 Aligning Material in Rows and Columns

Text can be aligned in rows and columns using the tabular environment.

\begin{tabular}[<pos>]{<column specifiers>}

This environment has a mandatory argument <column specifiers> that specifies how to align each column. Within <column specifiers>, there must be a specifier for each column. The three basic are: r (right aligned), l (left aligned) and c (centred). (Make sure you don't confuse l (the letter “ell”) with 1 (the digit one).) The optional argument <pos> is covered later.

Example:

Three columns (left, centred, centred):

\begin{tabular}{lcc}

Another Example:

Four columns (left, centred, centred, right):

\begin{tabular}{lccr}

The r, l and c specifiers don't allow line breaks or paragraphs within a cell. It's not a good idea to have too much text in a cell, but if it's required you can use

p{<width>}

which indicates a paragraph cell of the given width.

Example:

Three columns (paragraph of width 1in, centred, right):

\begin{tabular}{p{1in}cr}

The paragraph cell will be formatted fully justified, which is often inappropriate for a narrow block of text. The array package provides

>{<declaration>}

which can be used directly in front of the l, c, r or p column specifiers. This inserts <declaration> in front of the entries for that column, so it can be used to insert, say, \raggedright.

Example:

Three columns, the first left justified where each entry is in bold, the second a paragraph column of width 1in set to ragged right and the third centered:

\begin{tabular}{>{\bfseries}l>{\raggedright}p{1in}c}

The array package also provides

<{<declaration>}

which can be used directly after the l, c, r or p column specifiers. This inserts <declaration> after the entries for that column.

Inter-Column Gap:

The gap between columns is given by twice the value of the length register:

\tabcolsep

A gap of \tabcolsep is also inserted before the first column and after the last column. This length can be changed using one of the commands described in §2.17. Lengths. For example:

\setlength{\tabcolsep}{4pt}

This will put an 8pt gap between columns and a 4pt gap before the first column and after the last column.

The column specifiers can also include:

@{<inter-column text>}

This inserts <inter-column text> at that place on each row of the table, replacing the default inter-column gap.

Example:

Suppose we want a centred first column, a right justified second column and a left justified third column with a dot between the second and third columns:

\begin{tabular}{cr@{.}l}

Alternatively, you may want a larger gap between groups of columns, for example, two groups of three left justified columns:

This uses the command:

\hspace{<length>}

which inserts a horizontal space of a given length. In this case, four times the value of \tabcolsep. This makes the gap between the third and fourth columns twice as wide as the gap between the other columns.


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs