Skip to main content

13.10.5 Tables in LaTeX export

The LaTeX export back-end can pass several LaTeX attributes for table contents and layout. Besides specifying a label (see Internal Links) and a caption (see Captions), the other valid LaTeX attributes include:

β€˜:mode’​

The LaTeX export back-end wraps the table differently depending on the mode for accurate rendering of math symbols. Mode is either β€˜table’, β€˜math’, β€˜inline-math’ or β€˜verbatim’.

For β€˜math’ or β€˜inline-math’ mode, LaTeX export back-end wraps the table in a math environment, but every cell in it is exported as-is. The LaTeX export back-end determines the default mode from org-latex-default-table-mode. The LaTeX export back-end merges contiguous tables in the same mode into a single environment.

β€˜:environment’​

Set the default LaTeX table environment for the LaTeX export back-end to use when exporting Org tables. Common LaTeX table environments are provided by these packages: tabularx, longtable, array, tabu, and bmatrix. For packages, such as tabularx and tabu, or any newer replacements, include them in the org-latex-packages-alist variable so the LaTeX export back-end can insert the appropriate load package headers in the converted LaTeX file. Look in the docstring for the org-latex-packages-alist variable for configuring these packages for LaTeX snippet previews, if any.

β€˜:caption’​

Use β€˜CAPTION’ keyword to set a simple caption for a table (see Captions). For custom captions, use β€˜:caption’ attribute, which accepts raw LaTeX code. β€˜:caption’ value overrides β€˜CAPTION’ value.

β€˜:float’​

β€˜:placement’​

The table environments by default are not floats in LaTeX. To make them floating objects use β€˜:float’ with one of the following options: β€˜sideways’, β€˜multicolumn’, β€˜t’, and β€˜nil’.

LaTeX floats can also have additional layout β€˜:placement’ attributes. These are the usual β€˜[h t b p ! H]’ permissions specified in square brackets. Note that for β€˜:float sideways’ tables, the LaTeX export back-end ignores β€˜:placement’ attributes.

β€˜:align’​

β€˜:font’​

β€˜:width’​

The LaTeX export back-end uses these attributes for regular tables to set their alignments, fonts, and widths.

β€˜:spread’​

When β€˜:spread’ is non-nil, the LaTeX export back-end spreads or shrinks the table by the β€˜:width’ for tabu and longtabu environments. β€˜:spread’ has no effect if β€˜:width’ is not set.

β€˜:booktabs’​

β€˜:center’​

β€˜:rmlines’​

All three commands are toggles. β€˜:booktabs’ brings in modern typesetting enhancements to regular tables. The booktabs package has to be loaded through org-latex-packages-alist. β€˜:center’ is for centering the table. β€˜:rmlines’ removes all but the very first horizontal line made of ASCII characters from β€œtable.el" tables only.

β€˜:math-prefix’​

β€˜:math-suffix’​

β€˜:math-arguments’​

The LaTeX export back-end inserts β€˜:math-prefix’ string value in a math environment before the table. The LaTeX export back-end inserts β€˜:math-suffix’ string value in a math environment after the table. The LaTeX export back-end inserts β€˜:math-arguments’ string value between the macro name and the table’s contents. β€˜:math-arguments’ comes in use for matrix macros that require more than one argument, such as β€˜qbordermatrix’.

LaTeX table attributes help formatting tables for a wide range of situations, such as matrix product or spanning multiple pages:

#+ATTR_LATEX: :environment longtable :align l|lp{3cm}r|l
| ... | ... |
| ... | ... |

#+ATTR_LATEX: :mode math :environment bmatrix :math-suffix \times
| a | b |
| c | d |
#+ATTR_LATEX: :mode math :environment bmatrix
| 1 | 2 |
| 3 | 4 |

Set the caption with the LaTeX command β€˜\bicaption{HeadingA}{HeadingB}’:

#+ATTR_LATEX: :caption \bicaption{HeadingA}{HeadingB}
| ... | ... |
| ... | ... |