# tabular (LaTeX environment)

133pages on
this wiki

The tabular is the de-facto way of presenting tabular data in LaTeX.

## Basic Example Edit

\begin{table}[H]
\begin{tabular}{|l|l|l|l|l|l|l|l|l|l|l|l|l|}  \hline
\multirow{2}{*}{Services/NFPs} & \multicolumn{3}{l}{Performance Rate} & \multicolumn{2}{l}{Privacy} & \multicolumn{2}{l}{Security} & \multicolumn{3}{l}{Cost} & \multirow{2}{*}{L} & \multirow{2}{*}{Rank} \\
& w          & v          & E          & w             & E           & w              & E           & w       & v    & E       &                    &                       \\ \hline

Google                         & 0.1        & 0.8        & 0.75       & 0.1           & 1           & 0.1            & 1           & 0.5     & 1    & 1       & 0.7                & 2                     \\ \hline
Yahoo                          & 0.1        & 0.5        & 0.00       & 0.1           & 0           & 0.1            & 0           & 0.5     & 2    & 0.75    & 0.37               & 3                     \\ \hline
Exalead                        & 0.1        & 0.9        & 1.00       & 0.1           & 1           & 0.1            & 1           & 0.5     & 1    & 1       & 0.8                & 1   \\ \hline
\end{tabular}
\label{t9}
\caption{Ranking Based on User context}
\end{table}


Columns are separated by &, and \\ ends a row.

 dd dd dd dd dd dd 3 8 9 0 -5 1 2 1 2 4 4 1 2 1 2 3 5 1 3 1 1 1 1 1 5 11 1 1 1 1 76 1 1 1 1 1 1 11 1 1 1 1

LaTeX doesn't require any packages to use tabular by itself, so tabular is ubiquitous. The limitations of tabular are that it doesn't add sufficient whitespace around cells. Though it's not a limitation, many users add unnecessary vertical lines and double lines to their tables.

The booktabs package has a few commands that vastly improve the quality of tabular's tables, and the documentation for booktabs has some advice on typesetting tables properly.

## Column Definition Edit

A tabular environment takes one required parameter, the column definition.

\begin{tabular}{lrcp{0.5in}}
left aligned & right aligned & centered & set in a 0.5 inch parbox.
\end{tabular}


To repeat a series of columns, *{num}{form} may be used, e.g. *{3}{lr} is the same as lrlrlr.

Not recommended (and does not work as expected with booktabs) is the use of | and || to add vertical and double-vertical lines between columns.

To add some common text between two columns, use @{text} in the column definition.

## Lines / Rules Edit

As shown in the example in the beginning, the \hline command draws a horizontal line after the header row. To draw a line between subsequent rows, use \cline.

It is not necessary to draw a line between every row in a table.

## Layout Edit

A tabular environment is rendered inline as a single large character. An optional parameter controls the position of the float. By default, a tabular is aligned vertically centered with the text baseline.

\begin{tabular}[t]{lll}


The above example would align the top of the tabular with the text baseline, a b would align the bottom.

## Floating tabular Edit

To make the table float, simply include it in a table environment or a figure environment.

\begin{table}
\caption{Caption needs to be before the label.}
\centering
\begin{tabular}{lll}
...
\end{tabular}
\label{tbl:tablelabel}
\end{table}

See example at \autoref{tbl:tablelabel}.


The \centering command may be preferable to the center environment in a float, as the center environment will add a paragraph and create extra whitespace in the float.

A tabular environment may be nested within a minipage to allow side-by-side tables within a table or figure environment, or to place an image next to a table.

\begin{figure}
\begin{minipage}{2in}
... image ...
\end{minipage}
\begin{minipage}{2in}
\begin{tabular}{lll}
... table ...
\end{tabular}
\end{minipage}
\end{figure}


## Other packages Edit

• The ctable package allows captioned floating tables, with table footnotes properly laid out. It is also somewhat less wordy.
• For an alternative approach to side by side tables, try the subfigure package. This also removes the need for specifying subtable width.
• For handling tables that span pages, longtable.
• The tabularx package
Qasim