Next: Translator functions, Previous: Radio tables, Up: Tables in arbitrary syntax [Contents][Index]

#### A.6.2 A LaTeX example of radio tables

The best way to wrap the source table in LaTeX is to use the `comment` environment provided by `comment.sty`. It has to be activated by placing `\usepackage{comment}` into the document header. Orgtbl mode can insert a radio table skeleton181 with the command `M-x orgtbl-insert-radio-table RET`. You will be prompted for a table name, let’s say we use ‘`salesfigures`’. You will then get the following template:

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

The `#+ORGTBL: SEND` line tells Orgtbl mode to use the function `orgtbl-to-latex` to convert the table into LaTeX and to put it into the receiver location with name `salesfigures`. You may now fill in the table—feel free to use the spreadsheet features182:

    % 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}

When you are done, press `C-c C-c` in the table to get the converted table inserted between the two marker lines.

Now let’s assume you want to make the table header by hand, because you want to control how columns are aligned, etc. In this case we make sure that the table translator skips the first 2 lines of the source table, and tell the command to work as a splice, i.e., to not produce header and footer commands of the target table:

    \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. It uses a `tabular` environment to typeset the table and marks horizontal lines with `\hline`. Furthermore, it interprets the following parameters (see also see Translator functions):

`:splice nil/t`

  When set to t, return only table body lines, don’t wrap them into a tabular environment. Default is `nil`.

`:fmt fmt`

  A format to be used to wrap each field, it should contain `%s` for the original field value. For example, to wrap each field value in dollars, you could use `:fmt "$%s$"`. This may also be a property list with column numbers and formats, for example `:fmt (2 "$%s$" 4 "%s\\%%")`. A function of one argument can be used in place of the strings; the function must return a formatted string.

`:efmt efmt`

  Use this format to print numbers with exponentials. The format should have `%s` twice for inserting mantissa and exponent, for example `"%s\\times10^{%s}"`. The default is `"%s\\,(%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. Similar to `fmt`, functions of two arguments can be supplied instead of strings.

#### Footnotes

### (181)

By default this works only for LaTeX, HTML, and Texinfo. Configure the variable `orgtbl-radio-table-templates` to install templates for other modes.

### (182)

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`.

Next: Translator functions, Previous: Radio tables, Up: Tables in arbitrary syntax [Contents][Index]