[Univ of Cambridge] [Dept of Engineering]
next up previous contents
Next: Array Up: Environments Previous: Listing Items

Tabular

Tabular output is supported. When you create the environment you specify how many columns to have and how the contents are to be aligned (use l, c or r to represent each column with either left, center or right alignment) and where you want vertical lines (use |). The contents of the columns are separated by a `&' and rows by \\. Here's a simple example
\begin{tabular}{l|c|r}
left & centre & right\\
more left & more centre & more right\\
\end{tabular}

left centre right
more left more centre more right

To draw a full horizontal line, use \hline otherwise draw a line across selected columns using \cline. The \multicolumn command allows items to span columns. It takes as its first argument the number of columns to span. The following, more complicated example shows how to use these facilities.

\begin{tabular}{||l|lr||} \hline
\textbf{Veg}  & \multicolumn{2}{|c||}{\textbf{Detail}}\\\hline
carrots    & per pound & \pounds 0.75 \\ \cline{2-3}
           & each      &         20p  \\ \hline
mushrooms  & dozen     &         86p  \\ \cline{1-1} \cline{3-3}
toadstools & pick your own & free     \\ \hline
\end{tabular}

Veg Detail
carrots per pound £0.75
  each 20p
mushrooms dozen 86p
toadstools pick your own free

Tables won't continue on the next page if they're too long. The longtable or supertabular commands are needed to do this. See the Supertabular document for details and examples.

If the text in a column is too wide for the page, LATEX won't automatically text-wrap. Using p{5cm} instead of c, l or r in the tabular line will wrap-around the text in a 5 cm wide column.

There are various packages to assist with table creation. The array package adds some helpful features, including the ability to add formatting commands that control a whole column at a time, like so

\begin{tabular}{>{\ttfamily}l>{\scshape}c>{\Large}r}
      Text  & More Text & Large Text\\
      Left  & Centred   & Right
\end{tabular}

Text MORE TEXT Large Text
Left CENTRED Right

The rotating package is useful if you have a wide table that you want to display in landscape mode. You need to put your table inside \begin{sidewaystable} and \end{sidewaystable}.

If you want the table to have a caption and float (float up the page if it's started right near the foot of a page, for example), use

\begin{table}[htbp] 
\begin{tabular}...
...
\end{tabular}
\caption{...}
\end{table}
See section 4.7 for details.


next up previous contents
Next: Array Up: Environments Previous: Listing Items
Tim Love
1999-08-05