11

I am trying to customize the style of my org-mode tables when exported to Latex. I need to change their font face, their font size, the background color of the header and the background color of every other rows.

I see lots of discussions on how to do these things in pure LaTeX, using (or not) additional packages like pgfplotstable. But I would like to keep my document as 'org-mode' style as possible (for readability and because I also export in HTML).

There are ways to specify basic options via attribute, but it won't take me far enough: http://orgmode.org/manual/LaTeX-specific-attributes.html#LaTeX-specific-attributes

Is there a way to specify in an org-mode document that tables should use a particular format/structure (maybe in an external .sty) when exporting to LaTeX without messing the basic org-mode style table for other exports?

Thanks

xav
  • 225
  • 2
  • 8

2 Answers2

11

I'm doing mainly tables with the latex packages #+LaTeX_HEADER: \usepackage{booktabs}, \usepackage{xcolor}, \usepackage{colortbl} and \usepackage{siunitx}. Together with export attributes. For example:

#+LATEX: \definecolor{contiYellow}{RGB}{255,165,0} #+LATEX: \rowcolors[]{2}{contiYellow!5}{contiYellow!20} #+ATTR_LATEX: :align rS | *Type* | *Stiffness* in N/mm | |--------------------------------------------+---------------------| | Two bearings SKF in radial dir. (supplier) | 167800 | | Measurement bearings + rotor + device | 8398 | | Measurement device | 14753 | | Calculation rotor + bearings | 19500 | |--------------------------------------------+---------------------| | Sim. Rotor + "bearings" (package solid) | 50900 | | Sim. Rotor + "joints" (package solid) | 33320 | | Sim. Shaft + "bearings" (without package) | 12000 | | Sim. Shaft + "bearings" 10 mm | 20030 | #+TBLFM: @2$2=2*8.39e4 gives me

enter image description here

Dieter.Wilhelm
  • 1,836
  • 14
  • 25
  • cannot reproduce your output. Do you need anything else to run this? In particular latex complains about `\rowcolors[]{2}{contiYellow!5}{contiYellow!20}`, undefined control sequence. I have installed the 3 above packages. – DJJ Feb 27 '17 at 11:07
  • @DJJ: I'm sorry I forgot the give you right packages, I updated the answer. – Dieter.Wilhelm Feb 27 '17 at 11:53
  • Many thanks. But I still cannot reproduce the output. I get the same error. I guess the clue might be `:align rS`. I don't know what the S stands for. When using the `colortable` package one need to input ` \rowcolors[`, on each row. Have you found a way of looping through the rows? – DJJ Feb 27 '17 at 22:50
  • This `S` is for aligning numbers in a nicely way, for testing purposes you might use `l` or so. You might need `\usepackage{siunitx}` for it – Dieter.Wilhelm Feb 28 '17 at 05:56
  • 1
    Thanks. I think I have found the culprit. With `\usepackage[table]{xcolor}` it works as expected. Many thanks again – DJJ Feb 28 '17 at 09:55
  • @DJJ: You're very welcome! :-) – Dieter.Wilhelm Feb 28 '17 at 13:05
3

Depending on how much modification of the exported LaTeX you need, you might be able to use a filter, e.g. if all you need to do is wrap the latex in some additional LaTeX: http://orgmode.org/worg/exporters/filter-markup.html

If the changes are more complex, it sounds like you need a custom exporter, eg http://orgmode.org/worg/dev/org-export-reference.html where you could define a function that generates the latex code you want for a table.

John Kitchin
  • 11,555
  • 1
  • 19
  • 41