A little guide to LaTeX tables

How can one create tables in LaTeX? There are several different types of tables, but I'll show just one here. This should get you started, and you can use on-line guides and books in the library to help you make more sophisticated ones.

A LaTeX input file with simple tables



%\documentclass[twocolumn,11pt]{article}
\documentclass[11pt]{article}
\setlength{\textheight}{9truein}
\setlength{\topmargin}{-0.8truein}
\setlength{\parindent}{0pt}
\setlength{\parskip}{10pt}
\setlength{\columnsep}{.5in}
\newcommand{\beq}{\begin{equation}}
\newcommand{\eeq}{\end{equation}}

\begin{document}

As usual, this 
\LaTeX \ document contains a bunch of lines
at the beginning which include certain template files, etc.

In order to create a table, we use the usual
``begin'' and ``end'' commands to define a section
of the input file which will go into the table.
The name of this environment is {\bf tabular}.
The {\bf tabular} environment requires that we
immediately provide the basic layout of the table
within a pair of curly brackets.
To specify a table with two columns, put two
letters between the curly brackets, like this:

\begin{verbatim}
\begin{tabular}{l r}
  1  &  222    \\
  33333  &  4  \\
\end{tabular}
\end{verbatim}

The resulting table looks like this:

\begin{tabular}{l r}
  1  &  222    \\
  33333  &  4  \\
\end{tabular}

Inside the {\bf tabular} section,
use ampersand characters \& to separate
the columns, and place a double backslash 
$\backslash \backslash$
at the end of each line.

The letter ``l'' means ``make each element
inside the column left-justified'', 
while ``r'' means ``right-justified'' and
``c'' means ``centered.''
If your table is full of numbers, then probably
right-justified is a good idea; 
if the table is full of text, then perhaps left-justified
is better.

The following table has one left-justified column,
then a centered column,
and finally a right-justified column.

\begin{verbatim}
\begin{tabular}{l c r}
  left for me & centered!  &  this is right  \\
    short     &  sweet     &  terse \\
  avoid verbosity & lots of letters here &  blah blah blah blah  \\
\end{tabular}
\end{verbatim}

\begin{tabular}{l c r}
  left for me & centered!  &  this is right  \\
    short     &  sweet     &  terse \\
  avoid verbosity & lots of letters here &  blah blah blah blah  \\
\end{tabular}


\vfill
\eject


You can get a little fancy by adding horizontal
and vertical lines to your table in a relatively
simple manner:
use vertical bar characters in the ``table setup'' argument,
before or after or between the letters for each column.

\begin{verbatim}
\begin{tabular}{| l | r | }
  1  &  222    \\
  33333  &  4  \\
\end{tabular}
\end{verbatim}


\begin{tabular}{| l | r | }
  1  &  222    \\
  33333  &  4  \\
\end{tabular}


You can add horizontal lines between rows of the table
using the $\backslash{\rm hline}$  command:

\begin{verbatim}
\begin{tabular}{ l  r  }
 \hline
  1  &  222    \\
 \hline
  33333  &  4  \\
 \hline
\end{tabular}
\end{verbatim}


\begin{tabular}{ l  r  }
 \hline
  1  &  222    \\
 \hline
  33333  &  4  \\
 \hline
\end{tabular}


It's often nice to be able to add a title to the
table which spans the entire width, across all the
columns. 
You can use the $\backslash{\rm multiline}$
command to cause one entry to span multiple columns:


\begin{verbatim}
\begin{tabular}{ | l | r | }
 \multicolumn{2}{c}{A two-column title} \\
 \hline
  1  &  222    \\
 \hline
  33333  &  4  \\
 \hline
\end{tabular}
\end{verbatim}



\begin{tabular}{ | l | r | }
 \multicolumn{2}{c}{A two-column title} \\
 \hline
  1  &  222    \\
 \hline
  33333  &  4  \\
 \hline
\end{tabular}

\end{document}


If you run LaTeX on the above input source file, you'll produce a formatted document.


For more information