W3cubDocs

/LaTeX

tabular

Synopsis:

\begin{tabular}[pos]{cols}
  column 1 entry  &column 2 entry  ...  &column n entry \\
  ...
\end{tabular}

or

\begin{tabular*}{width}[pos]{cols}
  column 1 entry  &column 2 entry  ...  &column n entry \\
  ...
\end{tabular*}

Produce a table, a box consisting of a sequence of horizontal rows. Each row consists of items that are aligned vertically in columns. This illustrates many of the features.

\begin{tabular}{l|l}
  \textit{Player name}  &\textit{Career home runs}  \\ 
  \hline
  Hank Aaron  &755 \\
  Babe Ruth   &714
\end{tabular}

The output will have two left-aligned columns with a vertical bar between them. This is specified in tabular’s argument {l|l}. Put the entries into different columns by separating them with an ampersand, &. The end of each row is marked with a double backslash, \\. Put a horizontal rule below a row, after a double backslash, with \hline. After the last row the \\ is optional, unless an \hline command follows to put a rule below the table.

The required and optional arguments to tabular consist of:

pos

Optional. Specifies the table’s vertical position. The default is to align the table so its vertical center matches the baseline of the surrounding text. There are two other possible alignments: t aligns the table so its top row matches the baseline of the surrounding text, and b aligns on the bottom row.

This only has an effect if there is other text. In the common case of a tabular alone in a center environment this option makes no difference.

cols

Required. Specifies the formatting of columns. It consists of a sequence of the following specifiers, corresponding to the types of column and intercolumn material.

l

A column of left-aligned items.

r

A column of right-aligned items.

c

A column of centered items.

|

A vertical line the full height and depth of the environment.

@{text or space}

Insert text or space at this location in every row. The text or space material is typeset in LR mode. This text is fragile (see \protect).

If between two columns there is no @-expression then LaTeX’s book, article, and report classes will put on either side of each column a space of length \tabcolsep, which by default is 6pt. That is, by default adjacent columns are separated by 12pt (so \tabcolsep is misleadingly named since it is only half of the separation between tabular columns). In addition, a space of 6pt also comes before the first column and after the final column, unless you put a @{...} or | there.

If you override the default and use an @-expression then LaTeX does not insert \tabcolsep so you must insert any desired space yourself, as in @{\hspace{1em}}.

An empty expression @{} will eliminate the space. In particular, sometimes you want to eliminate the space before the first column or after the last one, as in the example below where the tabular lines need to lie on the left margin.

\begin{flushleft}
  \begin{tabular}{@{}l}
    ...
  \end{tabular}
\end{flushleft}

The next example shows text, a decimal point between the columns, arranged so the numbers in the table are aligned on it.

\begin{tabular}{r@{$.$}l}
  $3$ &$14$  \\
  $9$ &$80665$
\end{tabular}

An \extracolsep{wd} command in an @-expression causes an extra space of width wd to appear to the left of all subsequent columns, until countermanded by another \extracolsep. Unlike ordinary intercolumn space, this extra space is not suppressed by an @-expression. An \extracolsep command can be used only in an @-expression in the cols argument. Below, LaTeX inserts the right amount of intercolumn space to make the entire table 4 inches wide.

\begin{tabular*}{4in}{l@{\extracolsep{\fill}}l}
  Seven times down, eight times up \ldots 
  &such is life!
\end{tabular*}

To insert commands that are automatically executed before a given column, load the array package and use the >{...} specifier.

p{wd}

Each item in the column is typeset in a parbox of width wd, as if it were the argument of a \parbox[t]{wd}{...} command.

A line break double backslash \\ may not appear in the item, except inside an environment like minipage, array, or tabular, or inside an explicit \parbox, or in the scope of a \centering, \raggedright, or \raggedleft declaration (when used in a p-column element these declarations must appear inside braces, as with {\centering .. \\ ..}). Otherwise LaTeX will misinterpret the double backslash as ending the tabular row. Instead, to get a line break in there use \newline (see \newline).

*{num}{cols}

Equivalent to num copies of cols, where num is a positive integer and cols is a list of specifiers. Thus the specifier \begin{tabular}{|*{3}{l|r}|} is equivalent to the specifier \begin{tabular}{|l|rl|rl|r|}. Note that cols may contain another *-expression.

width

Required for tabular*, not allowed for tabular. Specifies the width of the tabular* environment. The space between columns should be rubber, as with @{\extracolsep{\fill}}, to allow the table to stretch or shrink to make the specified width, or else you are likely to get the Underfull \hbox (badness 10000) in alignment ... warning.

Parameters that control formatting:

\arrayrulewidth

A length that is the thickness of the rule created by |, \hline, and \vline in the tabular and array environments. The default is ‘.4pt’. Change it as in \setlength{\arrayrulewidth}{0.8pt}.

\arraystretch

A factor by which the spacing between rows in the tabular and array environments is multiplied. The default is ‘1’, for no scaling. Change it as \renewcommand{\arraystretch}{1.2}.

\doublerulesep

A length that is the distance between the vertical rules produced by the || specifier. The default is ‘2pt’.

\tabcolsep

A length that is half of the space between columns. The default is ‘6pt’. Change it with \setlength.

The following commands can be used inside the body of a tabular environment, the first two inside an entry and the second two between lines:

© 2007–2018 Karl Berry
Public Domain Software
http://latexref.xyz/tabular.html