4.6 Aligning Material in Rows and Columns
Text can be aligned in rows and columns using the tabular environment.
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.
Three columns (left, centred, centred):
Four columns (left, centred, centred, right):
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
which indicates a paragraph cell of the given width.
Three columns (paragraph of width 1in, centred, right):
The paragraph cell will be formatted fully justified, which is often inappropriate for a narrow block of text. The array package provides
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,
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:
The array package also provides
which can be used directly after the l, c, r or p column specifiers. This inserts <declaration> after the entries for that column.
The gap between columns is given by twice the value of the length register:
A gap of
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:
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:
This inserts <inter-column text> at that place on each row of the table, replacing the default inter-column gap.
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:
Alternatively, you may want a larger gap between groups of columns, for example, two groups of three left justified columns:
This uses the command:
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).