LaTeX Wiki
m (Undo revision 4322 by 139.222.200.156 (talk))
(24 intermediate revisions by 18 users not shown)
Line 1: Line 1:
  +
{{LenvTop}}
The [[Tabular (environment) | tabular environment]] is the de-facto way of presenting tabular data in LaTeX.
+
The '''tabular''' is the de-facto way of presenting tabular data in LaTeX.
   
 
== Basic Example ==
 
== Basic Example ==
  +
% Please add the following required packages to your document preamble:
 
  +
% \usepackage{multirow}
\begin{tabular}{llll}
 
  +
\begin{table}[]
Header & Header & Header & Header \\
 
  +
\centering
  +
\caption{My caption}
  +
\label{my-label}
 
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
 
\hline
 
\hline
  +
\multirow{3}{*}{Original material} & \multirow{3}{*}{Adsorbent Designation} & \multicolumn{4}{c|}{Incineration condition} & \multirow{3}{*}{Yield (\%)} & \multirow{3}{*}{Surface area (m2/g)} & \multirow{3}{*}{Place of study} & \multirow{3}{*}{Reference} \\ \cline{3-6}
data & data & data & data \\
 
  +
<nowiki> </nowiki> & & \multirow{2}{*}{Reactor/Furnace} & \multirow{2}{*}{Atmosphere} & \multirow{2}{*}{Temperature (°C)} & \multirow{2}{*}{Residence time (h)} & & & & \\
data & data & data & data \\
 
  +
<nowiki> </nowiki> & & & & & & & & & \\ \hline
data & data & data & data \\
 
  +
Sugarcane bagasse & MISCBA & microwave furnace & nitrogen & 900 & 3 & 23.4 & 599 & Malaysia & This study \\ \hline
data & data & data & data
 
  +
\multirow{2}{*}{Sugarcane bagasse} & \multirow{2}{*}{undigested sugarcane bagasse bio char} & \multirow{4}{*}{muffle furnace} & \multirow{4}{*}{–} & \multirow{4}{*}{550} & \multirow{4}{*}{2} & \multirow{4}{*}{–} & \multirow{2}{*}{14.1} & \multirow{4}{*}{USA} & \multirow{4}{*}<nowiki>{{[}58{]}} \\
  +
</nowiki> & & & & & & & & & \\ \cline{1-2} \cline{8-8}
  +
\multirow{2}{*}{Sugarcane bagasse} & \multirow{2}{*}{digested sugarcane bagasse bio char} & & & & & & 17.7 & & \\ \cline{8-8}
  +
<nowiki> </nowiki> & & & & & & & & & \\ \hline
  +
Rice husk & RP 600 & \multirow{2}{*}{furnace} & \multirow{2}{*}{limited oxygen} & 600 & \multirow{2}{*}{6} & 31.9 & \multirow{2}{*}{–} & \multirow{2}{*}{Greece} & \multirow{2}{*}<nowiki>{{[}59{]}}</nowiki> \\ \cline{1-2} \cline{5-5} \cline{7-7}
  +
Rice husk & RP 300 & & & 300 & & 32.8 & & & \\ \hline
  +
\multirow{5}{*}{Wheat residue} & WC - 300 & \multirow{5}{*}{–} & \multirow{5}{*}{limited oxygen} & 300 & \multirow{5}{*}{6} & \multirow{5}{*}{10-27} & 116 & \multirow{5}{*}{USA} & \multirow{5}{*}<nowiki>{{[}60{]}}</nowiki> \\ \cline{2-2} \cline{5-5} \cline{8-8}
  +
<nowiki> </nowiki> & WC - 400 & & & 400 & & & 189 & & \\ \cline{2-2} \cline{5-5} \cline{8-8}
  +
<nowiki> </nowiki> & WC - 500 & & & 500 & & & 309 & & \\ \cline{2-2} \cline{5-5} \cline{8-8}
  +
<nowiki> </nowiki> & WC - 600 & & & 600 & & & 438 & & \\ \cline{2-2} \cline{5-5} \cline{8-8}
  +
<nowiki> </nowiki> & WC - 700 & & & 700 & & & 363 & & \\ \hline
  +
\multirow{2}{*}{rapeseed plant stalk and straw} & \multirow{2}{*}{rapeseed plant stalk and straw bio char} & \multirow{2}{*}{tubular reactor} & \multirow{2}{*}{nitrogen} & \multirow{2}{*}{900} & \multirow{2}{*}{–} & \multirow{2}{*}{27.9} & \multirow{2}{*}{140.4} & \multirow{2}{*}{Turkey} & \multirow{2}{*}<nowiki>{{[}61{]}} \\
  +
</nowiki> & & & & & & & & & \\ \hline
  +
bamboo & bamboo char & – & limited oxygen & 1000 & – & – & 517.3 & China & {[}62{]} \\ \hline
  +
Orange peel & MOP 700 & – & – & 700 & 6 & – & 19.4 & China & {[}63{]} \\ \hline
  +
\multirow{2}{*}{empty fruit brunch} & \multirow{2}{*}{magnetic bio char} & \multirow{2}{*}{microwave muffle system} & \multirow{2}{*}{nitrogen} & \multirow{2}{*}{–} & \multirow{2}{*}{0.5} & \multirow{2}{*}{–} & \multirow{2}{*}{765} & \multirow{2}{*}{Malaysia} & \multirow{2}{*}<nowiki>{{[}64{]}} \\
  +
</nowiki> & & & & & & & & & \\ \hline
  +
\multirow{3}{*}{water treatment sludge} & WS 400 & \multirow{3}{*}{muffle furnace} & \multirow{3}{*}{limited oxygen} & 400 & \multirow{3}{*}{2} & \multirow{3}{*}{–} & 126.4 & \multirow{3}{*}{Japan} & \multirow{3}{*}<nowiki>{{[}65{]}}</nowiki> \\ \cline{2-2} \cline{5-5} \cline{8-8}
  +
<nowiki> </nowiki> & WS 600 & & & 600 & & & 114.4 & & \\ \cline{2-2} \cline{5-5} \cline{8-8}
  +
<nowiki> </nowiki> & WS 700 & & & 700 & & & 135.2 & & \\ \hline
  +
dairy waste & DAWC & muffle furnace & nitrogen & 600 & 2 & – & 161.2 & USA & {[}66{]} \\ \hline
 
\end{tabular}
 
\end{tabular}
  +
\end{table}
  +
  +
   
Columns are separated by <code>&</code>, and <code>\\</code> ends a row.
+
Columns are separated by <code>&</code>, and <code>\\</code> ends a row.
  +
{| class="article-table article-table-selected" style="width: 500px;" border="0" cellpadding="1" cellspacing="1"
  +
|+Summary of results on the scaled spiral samples. D0 is the diameter of the spiral, while w and s are the width of the patterned lines and their separation. f0 is the resonant frequency in the PEC limit. Add columns for Tc
  +
|-
  +
! scope="col" |dd
  +
! scope="col" |dd
  +
! scope="col" |dd
  +
! scope="col" |dd
  +
! scope="col" |dd
  +
! scope="col" |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
  +
|}
   
 
== Advantages and Limitations ==
 
== Advantages and Limitations ==
   
LaTeX doesn't require any packages to use <code>tabular</code> by itself, so tabular is
+
LaTeX doesn't require any packages to use <code>{{Lenv|tabular}}</code> 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.
 
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]] has a few commands that vastly improve the quality of <code>tabular</code>'s tables, and the documentation for [[booktabs]] has some advice on typesetting tables properly.
+
The {{Lpkg|booktabs}} package has a few commands that vastly improve the quality of <code>tabular</code>'s tables, and the documentation for booktabs has some advice on typesetting tables properly.
   
 
== Column Definition ==
 
== Column Definition ==
Line 31: Line 118:
 
To repeat a series of columns, <code>*{num}{form}</code> may be used, e.g. <code>*{3}{lr}</code> is the same as <code>lrlrlr</code>.
 
To repeat a series of columns, <code>*{num}{form}</code> may be used, e.g. <code>*{3}{lr}</code> is the same as <code>lrlrlr</code>.
   
Not recommended (and does not work as expected with [[booktabs]]) is the use of <code>|</code> and <code>||</code> to add vertical and double-vertical lines between columns.
+
Not recommended (and does not work as expected with {{Lpkg|booktabs}}) is the use of <code>|</code> and <code>||</code> to add vertical and double-vertical lines between columns.
   
To add some common text between two columns, use @{text} in the column definition.
+
To add some common text between two columns, use <code>{{Lcmd|@|at sign (LaTeX command)}}{text}</code> in the column definition.
   
 
== Lines / Rules ==
 
== Lines / Rules ==
Line 52: Line 139:
 
== Floating tabular ==
 
== Floating tabular ==
   
To make the table float, simply include it in a [[table]] environment or a [[figure]] environment.
+
To make the table float, simply include it in a {{Lenv|table}} environment or a {{Lenv|figure}} environment.
   
 
\begin{table}
 
\begin{table}
Line 65: Line 152:
 
See example at \autoref{tbl:tablelabel}.
 
See example at \autoref{tbl:tablelabel}.
   
The <code>\centering</code> 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.
+
The <code>\{{Lcmd|centering}}</code> command may be preferable to the {{Lenv|center}} environment in a float, as the center environment will add a paragraph and create extra whitespace in the float.
   
A <code>tabular</code> 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.
+
A <code>tabular</code> environment may be nested within a {{Lenv|minipage}} to allow side-by-side tables within a {{Lenv|table}} or {{Lenv|figure}} environment, or to place an image next to a table.
   
 
\begin{figure}
 
\begin{figure}
Line 83: Line 170:
 
== Other packages ==
 
== Other packages ==
   
* The [[ctable]] package allows captioned floating tables, with table footnotes properly laid out. It is also somewhat less wordy.
+
* The {{Lpkg|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 an alternative approach to side by side tables, try the {{Lpkg|subfigure}} package. This also removes the need for specifying subtable width.
* For handling tables that span pages, [[longtable]].
+
* For handling tables that span pages, {{Lpkg|longtable}}.
* The [[tabularx]] package
+
* The {{Lpkg|tabularx}} package
   
  +
{| class="article-table" style="width: 500px;" border="0" cellpadding="1" cellspacing="1"
  +
|-
  +
! scope="col" |
  +
{| class="article-table" style="width: 500px;" border="0" cellpadding="1" cellspacing="1"
  +
|+Qasim
  +
|-
  +
! scope="col" |
  +
! scope="col" |
  +
|-
  +
|
  +
|
  +
|-
  +
|
  +
|
  +
|}
  +
! scope="col" |
  +
|-
  +
|
  +
|
  +
|-
  +
|
  +
|
  +
|}
 
== External links ==
 
== External links ==
   
Line 93: Line 203:
 
* [http://en.wikibooks.org/wiki/LaTeX/Tables Wikibooks article on tables in LaTeX]
 
* [http://en.wikibooks.org/wiki/LaTeX/Tables Wikibooks article on tables in LaTeX]
 
* [http://www.vision.ime.usp.br/~jmena/misc/latex/tables_with_latex.pdf Guide to tables with LaTex]
 
* [http://www.vision.ime.usp.br/~jmena/misc/latex/tables_with_latex.pdf Guide to tables with LaTex]
  +
* [http://truben.no/latex/table/ A simple online LaTeX table editor]
  +
{{LenvBottom}}
 
[[Category:Layout]]
 
[[Category:Layout]]
 
[[Category:Environment]]
 
[[Category:Environment]]

Revision as of 18:20, 24 January 2018

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

Basic Example

% Please add the following required packages to your document preamble:
% \usepackage{multirow}
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
\hline
\multirow{3}{*}{Original material}              & \multirow{3}{*}{Adsorbent Designation}                   & \multicolumn{4}{c|}{Incineration condition}                                                                                                          & \multirow{3}{*}{Yield (\%)} & \multirow{3}{*}{Surface area (m2/g)} & \multirow{3}{*}{Place of study} & \multirow{3}{*}{Reference} \\ \cline{3-6}
                                                &                                                          & \multirow{2}{*}{Reactor/Furnace}         & \multirow{2}{*}{Atmosphere}     & \multirow{2}{*}{Temperature (°C)} & \multirow{2}{*}{Residence time (h)} &                             &                                      &                                 &                            \\
                                                &                                                          &                                          &                                 &                                   &                                     &                             &                                      &                                 &                            \\ \hline
Sugarcane bagasse                               & MISCBA                                                   & microwave furnace                        & nitrogen                        & 900                               & 3                                   & 23.4                        & 599                                  & Malaysia                        & This study                 \\ \hline
\multirow{2}{*}{Sugarcane bagasse}              & \multirow{2}{*}{undigested sugarcane bagasse bio char}   & \multirow{4}{*}{muffle furnace}          & \multirow{4}{*}{–}              & \multirow{4}{*}{550}              & \multirow{4}{*}{2}                  & \multirow{4}{*}{–}          & \multirow{2}{*}{14.1}                & \multirow{4}{*}{USA}            & \multirow{4}{*}{{[}58{]}}  \\
                                                 &                                                          &                                          &                                 &                                   &                                     &                             &                                      &                                 &                            \\ \cline{1-2} \cline{8-8}
\multirow{2}{*}{Sugarcane bagasse}              & \multirow{2}{*}{digested sugarcane bagasse bio char}     &                                          &                                 &                                   &                                     &                             & 17.7                                 &                                 &                            \\ \cline{8-8}
                                                &                                                          &                                          &                                 &                                   &                                     &                             &                                      &                                 &                            \\ \hline
Rice husk                                       & RP 600                                                   & \multirow{2}{*}{furnace}                 & \multirow{2}{*}{limited oxygen} & 600                               & \multirow{2}{*}{6}                  & 31.9                        & \multirow{2}{*}{–}                   & \multirow{2}{*}{Greece}         & \multirow{2}{*}{{[}59{]}}  \\ \cline{1-2} \cline{5-5} \cline{7-7}
Rice husk                                       & RP 300                                                   &                                          &                                 & 300                               &                                     & 32.8                        &                                      &                                 &                            \\ \hline
\multirow{5}{*}{Wheat residue}                  & WC - 300                                                 & \multirow{5}{*}{–}                       & \multirow{5}{*}{limited oxygen} & 300                               & \multirow{5}{*}{6}                  & \multirow{5}{*}{10-27}      & 116                                  & \multirow{5}{*}{USA}            & \multirow{5}{*}{{[}60{]}}  \\ \cline{2-2} \cline{5-5} \cline{8-8}
                                                & WC - 400                                                 &                                          &                                 & 400                               &                                     &                             & 189                                  &                                 &                            \\ \cline{2-2} \cline{5-5} \cline{8-8}
                                                & WC - 500                                                 &                                          &                                 & 500                               &                                     &                             & 309                                  &                                 &                            \\ \cline{2-2} \cline{5-5} \cline{8-8}
                                                & WC - 600                                                 &                                          &                                 & 600                               &                                     &                             & 438                                  &                                 &                            \\ \cline{2-2} \cline{5-5} \cline{8-8}
                                                & WC - 700                                                 &                                          &                                 & 700                               &                                     &                             & 363                                  &                                 &                            \\ \hline
\multirow{2}{*}{rapeseed plant stalk and straw} & \multirow{2}{*}{rapeseed plant stalk and straw bio char} & \multirow{2}{*}{tubular reactor}         & \multirow{2}{*}{nitrogen}       & \multirow{2}{*}{900}              & \multirow{2}{*}{–}                  & \multirow{2}{*}{27.9}       & \multirow{2}{*}{140.4}               & \multirow{2}{*}{Turkey}         & \multirow{2}{*}{{[}61{]}}  \\
                                                 &                                                          &                                          &                                 &                                   &                                     &                             &                                      &                                 &                            \\ \hline
bamboo                                          & bamboo char                                              & –                                        & limited oxygen                  & 1000                              & –                                   & –                           & 517.3                                & China                           & {[}62{]}                   \\ \hline
Orange peel                                     & MOP 700                                                  & –                                        & –                               & 700                               & 6                                   & –                           & 19.4                                 & China                           & {[}63{]}                   \\ \hline
\multirow{2}{*}{empty fruit brunch}             & \multirow{2}{*}{magnetic bio char}                       & \multirow{2}{*}{microwave muffle system} & \multirow{2}{*}{nitrogen}       & \multirow{2}{*}{–}                & \multirow{2}{*}{0.5}                & \multirow{2}{*}{–}          & \multirow{2}{*}{765}                 & \multirow{2}{*}{Malaysia}       & \multirow{2}{*}{{[}64{]}}  \\
                                                 &                                                          &                                          &                                 &                                   &                                     &                             &                                      &                                 &                            \\ \hline
\multirow{3}{*}{water treatment sludge}         & WS 400                                                   & \multirow{3}{*}{muffle furnace}          & \multirow{3}{*}{limited oxygen} & 400                               & \multirow{3}{*}{2}                  & \multirow{3}{*}{–}          & 126.4                                & \multirow{3}{*}{Japan}          & \multirow{3}{*}{{[}65{]}}  \\ \cline{2-2} \cline{5-5} \cline{8-8}
                                                & WS 600                                                   &                                          &                                 & 600                               &                                     &                             & 114.4                                &                                 &                            \\ \cline{2-2} \cline{5-5} \cline{8-8}
                                                & WS 700                                                   &                                          &                                 & 700                               &                                     &                             & 135.2                                &                                 &                            \\ \hline
dairy waste                                     & DAWC                                                     & muffle furnace                           & nitrogen                        & 600                               & 2                                   & –                           & 161.2                                & USA                             & {[}66{]}                   \\ \hline
\end{tabular}
\end{table}


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

Summary of results on the scaled spiral samples. D0 is the diameter of the spiral, while w and s are the width of the patterned lines and their separation. f0 is the resonant frequency in the PEC limit. Add columns for Tc
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

Advantages and Limitations

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

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

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

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

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}
  \qquad
  \begin{minipage}{2in}
    \begin{tabular}{lll}
      ... table ...
    \end{tabular}
  \end{minipage}
\end{figure}

Other packages

  • 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

External links