This is the official manual for the latest Org-mode release.

Table of Contents

Next: , Previous: Radio tables, Up: Tables in arbitrary syntax


A.6.2 A LaTeX example of radio tables

To wrap a source table in LaTeX, use the comment environment provided by comment.sty. To activate it, put \usepackage{comment} in the document header. Orgtbl mode inserts a radio table skeleton1 with the command M-x orgtbl-insert-radio-table RET, which prompts for a table name. For example, if ‘salesfigures’ is the name, the template inserts:

     % BEGIN RECEIVE ORGTBL salesfigures
     % END RECEIVE ORGTBL salesfigures
     \begin{comment}
     #+ORGTBL: SEND salesfigures orgtbl-to-latex
     | | |
     \end{comment}

The line #+ORGTBL: SEND tells Orgtbl mode to use the function orgtbl-to-latex to convert the table to LaTeX format, then insert the table at the target (receive) location named salesfigures. Now the table is ready for data entry. It can even use spreadsheet features2:

     % BEGIN RECEIVE ORGTBL salesfigures
     % END RECEIVE ORGTBL salesfigures
     \begin{comment}
     #+ORGTBL: SEND salesfigures orgtbl-to-latex
     | Month | Days | Nr sold | per day |
     |-------+------+---------+---------|
     | Jan   |   23 |      55 |     2.4 |
     | Feb   |   21 |      16 |     0.8 |
     | March |   22 |     278 |    12.6 |
     #+TBLFM: $4=$3/$2;%.1f
     % $ (optional extra dollar to keep font-lock happy, see footnote)
     \end{comment}

After editing, C-c C-c inserts translated table at the target location, between the two marker lines.

For hand-made custom tables, note that the translator needs to skip the first two lines of the source table. Also the command has to splice out the target table without the header and footer.

     \begin{tabular}{lrrr}
     Month & \multicolumn{1}{c}{Days} & Nr.\ sold & per day\\
     % BEGIN RECEIVE ORGTBL salesfigures
     % END RECEIVE ORGTBL salesfigures
     \end{tabular}
     %
     \begin{comment}
     #+ORGTBL: SEND salesfigures orgtbl-to-latex :splice t :skip 2
     | Month | Days | Nr sold | per day |
     |-------+------+---------+---------|
     | Jan   |   23 |      55 |     2.4 |
     | Feb   |   21 |      16 |     0.8 |
     | March |   22 |     278 |    12.6 |
     #+TBLFM: $4=$3/$2;%.1f
     \end{comment}

The LaTeX translator function orgtbl-to-latex is already part of Orgtbl mode and uses tabular environment by default to typeset the table and mark the horizontal lines with \hline. For additional parameters to control output, see Translator functions:

:splice nil/t
When non-nil, returns only table body lines; not wrapped in tabular environment. Default is nil.
:fmt fmt
Format to warp each field. It should contain %s for the original field value. For example, to wrap each field value in dollar symbol, you could use :fmt "$%s$". Format can also wrap a property list with column numbers and formats, for example :fmt (2 "$%s$" 4 "%s\\%%"). In place of a string, a function of one argument can be used; the function must return a formatted string.
:efmt efmt
Format numbers as exponentials. The spec should have %s twice for inserting mantissa and exponent, for example "%s\\times10^{%s}". This may also be a property list with column numbers and formats, for example :efmt (2 "$%s\\times10^{%s}$" 4 "$%s\\cdot10^{%s}$"). After efmt has been applied to a value, fmt will also be applied. Functions with two arguments can be supplied instead of strings. By default, no special formatting is applied.

Footnotes

[1] By default this works only for LaTeX, HTML, and Texinfo. Configure the variable orgtbl-radio-table-templates to install templates for other export formats.

[2] If the ‘#+TBLFM’ line contains an odd number of dollar characters, this may cause problems with font-lock in LaTeX mode. As shown in the example you can fix this by adding an extra line inside the comment environment that is used to balance the dollar expressions. If you are using AUCTeX with the font-latex library, a much better solution is to add the comment environment to the variable LaTeX-verbatim-environments.