# Fixing tables in org-mode LaTeX exports

Tags:

## The Problem

Table formatting in PDFs exported via $$\LaTeX$$ back-end in Emacs org-mode1. Depending on the tables and the amount of text around them, tables are sometimes not produced where they are located in the org file. Let’s make these tables render exactly where we add them in the org file.

Table captions in these PDFs are produced above the table instead of below as is common in scientific documents.

Some tweaks that render them better are elaborated below. Thanks StackOverflow2 , 3

## Table Positioning

This is how I got sticky positioning working. Put this in the header (top part) of the org file:

#+LATEX_HEADER: \usepackage{float}


Then write tables like this:

#+CAPTION: ML Algorithms
#+NAME: ml-algos-table
#+ATTR_LATEX: :placement [H] :center t
|-------------------+--------------|
| ML Algorithm      | Type         |
|-------------------+--------------|
| Linear Regression | Supervised   |
| XGBoost           | Supervised   |
| k-NN              | Unsupervised |
|-------------------+--------------|


I learned that you cannot add #+LATEX: lines between #+CAPTION and the table. You can however add #+ATTR_LATEX: properties in between the two. The Org documentation4 explains how to use this.

## Caption Positioning

To change the caption positioning from above to below the tables, add this to your config for a global setting,

(setq org-latex-caption-above nil)


Or, add this to the top of your file for a file level setting. Remember to save and M-x revert-buffer to apply the setting.

#+BIND: org-latex-caption-above nil