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

Table of Contents

Next: , Previous: Creating one-off styles, Up: Advanced topics in ODT export


Customizing tables in ODT export

Override the default table format by specifying a custom table style with the #+ATTR_ODT line. For a discussion on default formatting of tables see Tables in ODT export.

This feature closely mimics the way table templates are defined in the OpenDocument-v1.2 specification.1

For quick preview of this feature, install the settings below and export the table that follows:

     (setq org-odt-table-styles
           (append org-odt-table-styles
                 '(("TableWithHeaderRowAndColumn" "Custom"
                     ((use-first-row-styles . t)
                      (use-first-column-styles . t)))
                     ("TableWithFirstRowandLastRow" "Custom"
                      ((use-first-row-styles . t)
                      (use-last-row-styles . t))))))
     #+ATTR_ODT: :style TableWithHeaderRowAndColumn
     | Name  | Phone | Age |
     | Peter |  1234 |  17 |
     | Anna  |  4321 |  25 |

The example above used ‘Custom’ template and installed two table styles ‘TableWithHeaderRowAndColumn’ and ‘TableWithFirstRowandLastRow’. Important: The OpenDocument styles needed for producing the above template were pre-defined. They are available in the section marked ‘Custom Table Template’ in OrgOdtContentTemplate.xml (see Factory styles. For adding new templates, define new styles here.

To use this feature proceed as follows:

  1. Create a table template2

    A table template is set of ‘table-cell’ and ‘paragraph’ styles for each of the following table cell categories:

    The names for the above styles must be chosen based on the name of the table template using a well-defined convention.

    The naming convention is better illustrated with an example. For a table template with the name ‘Custom’, the needed style names are listed in the following table.

    Table cell type table-cell style paragraph style

    Body CustomTableCellCustomTableParagraph
    First column CustomFirstColumnTableCellCustomFirstColumnTableParagraph
    Last column CustomLastColumnTableCellCustomLastColumnTableParagraph
    First row CustomFirstRowTableCellCustomFirstRowTableParagraph
    Last row CustomLastRowTableCellCustomLastRowTableParagraph
    Even row CustomEvenRowTableCellCustomEvenRowTableParagraph
    Odd row CustomOddRowTableCellCustomOddRowTableParagraph
    Even column CustomEvenColumnTableCellCustomEvenColumnTableParagraph
    Odd column CustomOddColumnTableCellCustomOddColumnTableParagraph

    To create a table template with the name ‘Custom’, define the above styles in the <office:automatic-styles>...</office:automatic-styles> element of the content template file (see Factory styles).

  2. Define a table style3

    To define a table style, create an entry for the style in the variable org-odt-table-styles and specify the following:

    For example, the entry below defines two different table styles ‘TableWithHeaderRowAndColumn’ and ‘TableWithFirstRowandLastRow’ based on the same template ‘Custom’. The styles achieve their intended effect by selectively activating the individual cell styles in that template.

              (setq org-odt-table-styles
                    (append org-odt-table-styles
                            '(("TableWithHeaderRowAndColumn" "Custom"
                               ((use-first-row-styles . t)
                                (use-first-column-styles . t)))
                              ("TableWithFirstRowandLastRow" "Custom"
                               ((use-first-row-styles . t)
                                (use-last-row-styles . t))))))
    
  3. Associate a table with the table style

    To do this, specify the table style created in step (2) as part of the ATTR_ODT line as shown below.

              #+ATTR_ODT: :style "TableWithHeaderRowAndColumn"
              | Name  | Phone | Age |
              | Peter |  1234 |  17 |
              | Anna  |  4321 |  25 |
    

Footnotes

[1] OpenDocument-v1.2 Specification

[2] See the <table:table-template> element of the OpenDocument-v1.2 specification

[3] See the attributes table:template-name, table:use-first-row-styles, table:use-last-row-styles, table:use-first-column-styles, table:use-last-column-styles, table:use-banding-rows-styles, and table:use-banding-column-styles of the <table:table> element in the OpenDocument-v1.2 specification