Next: Validating OpenDocument XML, Previous: Creating one-off styles, Up: Advanced topics in ODT export [Contents][Index]

#### 12.9.11.4 Customizing tables in ODT export

You can override the default formatting of the table 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.157

#### Custom table styles: an illustration

To have a quick preview of this feature, install the below setting 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 |

In the above example, you used a template named ‘`Custom`’ and installed two table styles with the names ‘`TableWithHeaderRowAndColumn`’ and ‘`TableWithFirstRowandLastRow`’. (Important: The OpenDocument styles needed for producing the above template have been pre-defined for you. These styles are available under the section marked ‘`Custom Table Template`’ in `OrgOdtContentTemplate.xml` (see Factory styles). If you need additional templates you have to define these styles yourselves.

#### Custom table styles: the nitty-gritty

To use this feature proceed as follows:

1. Create a table template158

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

   - - Body
   - - First column
   - - Last column
   - - First row
   - - Last row
   - - Even row
   - - Odd row
   - - Even column
   - - Odd Column

   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 | ‘`CustomTableCell`’ | ‘`CustomTableParagraph`’
   First column | ‘`CustomFirstColumnTableCell`’ | ‘`CustomFirstColumnTableParagraph`’
   Last column | ‘`CustomLastColumnTableCell`’ | ‘`CustomLastColumnTableParagraph`’
   First row | ‘`CustomFirstRowTableCell`’ | ‘`CustomFirstRowTableParagraph`’
   Last row | ‘`CustomLastRowTableCell`’ | ‘`CustomLastRowTableParagraph`’
   Even row | ‘`CustomEvenRowTableCell`’ | ‘`CustomEvenRowTableParagraph`’
   Odd row | ‘`CustomOddRowTableCell`’ | ‘`CustomOddRowTableParagraph`’
   Even column | ‘`CustomEvenColumnTableCell`’ | ‘`CustomEvenColumnTableParagraph`’
   Odd column | ‘`CustomOddColumnTableCell`’ | ‘`CustomOddColumnTableParagraph`’

   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 style159

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

   - - the name of the table template created in step (1)
   - - the set of cell styles in that template that are to be activated

   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

### (157)

OpenDocument-v1.2 Specification

### (158)

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

### (159)

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

Next: Validating OpenDocument XML, Previous: Creating one-off styles, Up: Advanced topics in ODT export [Contents][Index]