Tables are very similar to arrays in mathematics, but
tables often contain words and have lines separating rows
and columns. LATEX has a tabular environment that is almost
identical to the array environment. As with arrays,
the command that begins the environment has an extra
parameter that specifies the format of the columns.
This format uses l, r, and c to for left-, right- and
center-justified columns. It can also include |
characters to indicate where vertical lines are
to be drawn in the table. For example,
\begin{tabular}{|r||cc|}
Will produce a table with three columns. The entries
in the first column are right-justified; the other two
columns are center-justified. There is a vertical line
on each side of the table, a double vertical line
between the first and second column, and no line
between the second column and the third.
In the data for the table, the end of a row is marked
with \\
. Items on a row are separated with &
.
You can also put the command \hline
before the
first row, after the last row, or between rows to indicate
places where a horizontal line is supposed to be drawn
across the table. If you want to draw a horizontal
line just across columns 2 through 4, use
\cline{2-4}
.
Sometimes, you would like to have one item span several columns.
You can do this by using a \multicolumn
command
in your table data. This command takes the form
\multicolumn{ct}{fmt}{item}
where ct
is a number that says how many columns should be covered;
fmt contains exactly one r, l, or c to say how
the item should be justified (and can also contain one or more
|
characters to draw vertical lines); and
item is the actual text of the item.
The standard look of tables is a bit cramped vertically
for my taste. Adding the command
\renewcommand{\arraystretch}{1.2}
to the
document preamble will stretch arrays and tables
vertically by a factor of 1.2, giving them a
less cramped appearance.
Note: To center a table on the page, put it in a center
environment, that is, between \begin{center}
and \end{center}
.