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

12.8.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.1

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-export-odt-table-styles
           (append org-export-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 template2

    A table template is nothing but a 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-export-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-export-odt-table-styles
                    (append org-export-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