Notes about open source software, computers, other stuff.

Hiding columns in LaTeX export of org-mode tables

Today I was working on an Emacs org-mode document that I wanted to export to PDF. The document contained several tables and for the PDF export I wanted to hide one of the columns in the table. Of course I could have removed the column in the org source, but since I might need it in the future that wasn’t really an option.

Searching the internet I came across this e-mail discussion on the org-mode mailing list, where radio tables were suggested. I briefly tried to get that working, but it seems that this is more of an option if you are working in e.g. a LaTeX document and want to use org-style formatted tables.

So I tried another search, this time on how to hide columns in LaTeX, having the idea in mind that I could then use that to fix the org-mode export. Thanks to question on I came up with the followin solution:

First add the following lines at the top of the org file, after the regular org-mode header (if you have one):

#+LATEX_HEADER: \usepackage{array}
#+LATEX_HEADER: \newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}

This defines a new column type with the name H (for ‘hidden’). Next, just before the table, simply add an #+ATTR_LATEX: attribute (see the org-mode manual):

#+ATTR_LATEX: :align lHl
| col 1 | to be hidden | col3   |
|     1 | secret       | info 1 |
|     2 | private      | info 2 |
|     3 | hidden       | info 3 |

When you export this to PDF (via C-c C-e lo) the table in the PDF only contains the first and last column.

1 Comment

  1. David

    I’ve been needing this hack for a while. Love it!. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2020 Lennart's weblog

Theme by Anders NorenUp ↑