table-written LaTeX by example: tables

Sometimes, technical information can best be represented by a table rather than in words. Use this sample document as a guide for creating tables in LaTeX.

LaTeX is a popular markup system for scientific and engineering documents. Many engineers and scientists prefer LaTeX to submit technical articles and conference proceedings, especially for any documents that include mathematics, such as equations.

Sometimes, technical information can best be represented by a table rather than in words. Tables can highlight relationships between information, list data or observations from experiments, or order information by category.

Basic tables

Use \begin{tabular} to start a table in LaTeX, and specify the alignment of each column. For example, center data with c, align text to the left with l, and align to the right with r. Use the vertical bar | to indicate any separator lines between columns.

Your data goes between \begin{tabular} and \end{tabular}. Use & to separate column data, and \\ to indicate the end of a row. If you want to include a separator line between any rows, you need to add \hline manually.

Tables by example

Let's look at a sample LaTeX document that includes several versions of the same basic 3-column and 3-row table. The first example generates a plain, unstyled table with centered content. The next two samples generate tables with separator lines between columns and rows. The last example centers the table and uses left, center, and right justification for each column.

\documentclass{article}
\begin{document}

\LaTeX\ can generate tables fairly easily.
To start a new table, use a \texttt{tabular} block and specify how
the cell data should be arranged, like this sample table that has
three centered columns and three rows:

\vspace{.2in}

\begin{tabular}{ c c c }
one & two & three \\
four & five & six \\
seven & eight & nine
\end{tabular}

\vspace{.5in}

To place separator lines between each column, use the vertical bar:

\vspace{.2in}

\begin{tabular}{ c|c|c }
one & two & three \\
four & five & six \\
seven & eight & nine
\end{tabular}

\vspace{.5in}

You need to add separator lines between rows manually using
\texttt{hline}:

\vspace{.2in}

\begin{tabular}{ c|c|c }
one & two & three \\
\hline
four & five & six \\
\hline
seven & eight & nine
\end{tabular}

\vspace{.5in}

Let's update the example with outside borders, and left and right
justification on cells.
To center the table, put it in a \texttt{center} block:

\vspace{.2in}

\begin{center}
\begin{tabular}{|l|c|r|}
\hline
one & two & three \\
\hline
four & five & six \\
\hline
seven & eight & nine \\
\hline
\end{tabular}
\end{center}

\end{document}

Compare this LaTeX source with the final document for a practical demonstration of basic tables in LaTeX:

Sample tables in LaTeX

Sample tables in LaTeX

Note that by default, LaTeX tables cannot align numerical data on the decimal point. To align on decimal points, refer to the dcolumn package in LaTeX, which also requires the array package. You can also find more information in the LaTeX 2ε for authors (PDF) user guide, found in the LaTeX general documentation. Wikibooks also provides a helpful description of LaTeX tables.