# LaTeX Table Is Out of Place | Org-mode

I am making my tables in pure LaTeX becuase Org-mode doesn't have the functionality to create what I want. My problem is, I am pasting the LaTeX code for the table under a heading but when I get the pdf export, I see that the table has moved under another heading, above some other text.

I had this happen to me before in this document again with an image (since I had used #+CAPTION on it) but using \usepackage{placeins} in LaTeX header and \FloatBarrier at the end of the image did work. I tried doing the same thing for the table but it simply won't work.

• The table is probably made into a float (check the exported .tex file): floats ... float :-) Please post the relevant snippet from the exported .tex file. – NickD Jan 19 at 14:58
• @NickD I uploaded the table here: link. I am not sure if it will help. Uploading th entire .tex file will be much more difficult as I will need to change its actual content. – abtoiew Jan 19 at 18:11
• No need: that was enough. You have a table environment surrounding the tabular. That is caused by the caption: Org mode exports captioned tables as floats (and that makes sense if you think about it). If you eliminate the #+CAPTION, that should export as just a tabular which is not a floating environment: it will not move around. – NickD Jan 19 at 18:59
• @NickD That is correct, #+CAPTION is what's causing the table to become a float just like an image with #+CAPTION. How do I go about fixing this issue while keeping the caption (because I do need it, writing a scientific document)? – abtoiew Jan 19 at 20:16
• The usual "solution" is what @mankoff suggests in his answer: #+LATEX_ATTR: :placement [!h]. Did you try that? What went wrong? – NickD Jan 19 at 20:40

Your preamble shows that you use the float package. When you use the float package, the correct placement parameter for right here is H. So write your table like this in the Org mode file:

#+ATTR_LATEX: :placement [H]
#+CAPTION: My Table
|  a |    b |
|----+------|
|  1 |    1 |
|  2 |    4 |
|  3 |    9 |
| .. |  ... |


Without the float package, @mankoff's answer stands: :placement [!h] is the best that you can do.

But note that float placement is a complicated problem: Lamport's book describing the method (Section C.9.1) devotes four pages to the description - there are six rules (that "you will have to read ... slowly and carefully to understand what LaTeX is doing") and fifteen formatting parameters. So if LaTeX seems to be doing something wrong, you will have to go back and figure out which rule you are breaking.

Float placement has a long, contentious history: see https://tex.stackexchange.com/questions/8625/force-figure-placement-in-text for some perspective.

EDIT: As the OP pointed out in the question and which I forgot about, he is NOT using Org mode tables. Instead he is inserting the table as raw LaTeX code (because Org mode can only deal with simple tables that don't have e.g. spanning columns). So all the talk about #ATTR_LATEX: is irrelevant in this case.

Org mode will deal with a raw LaTeX table in the Org mode file by exporting it verbatim into the resulting .tex file. So all the OP has to do in that case is make sure that the placement indicator is present in the raw LaTeX table (the following assumes that the float package is used for LaTeX: that enables the use of the H indicator; as pointed out above, without that package, the best one can do in order to place the table here is to use the !h placement indicator):

#+LATEX_HEADER: \usepackage{float}

* An Org mode table
Here comes an Org mode table:

#+ATTR_LATEX: :placement[H]
#+CAPTION: My Table
|  a |    b |
|----+------|
|  1 |    1 |
|  2 |    4 |
|  3 |    9 |
| .. |  ... |

* A raw LaTeX table

Here comes a raw LaTeX table - the spanning style column
could not be done with an Org mode table (but it could probably
be done with a table.el table - that's left as an exercise):

\begin{table}[H]
\caption{My raw \LaTeX table}
\centering
\begin{tabular}{|l|l|r|}    \hline\hline
\emph{type} & \multicolumn{2}{c|}{\emph{style}} \\ \hline
smart        & red    & short \\
rather silly & puce   & tall \\ \hline\hline
\end{tabular}
\end{table}



In general, it is always a good idea to look at the exported LaTeX file and see what Org mode did: even if you don't know any LaTeX, you should be able to figure out what needs to be done for simple changes and even if not, you can ask questions about it on the TeX SE site. IOW, Org mode export is enough for simple documents, but if you have something that is beyond what Org mode can do, you will need to learn some LaTeX. And this applies to the other exporters as well: Org mode can deal with 90% of what you need day to day, but you will need to know something about the target language in order to cover the remaining 10%.

• Changing it to #+ATTR_LATEX: :placement [H] did nothing different. Could it be because I am not using org-mode table format like |---| but directly a LaTeX table with \begin{table}[]? – abtoiew Jan 20 at 7:38
• I forgot about that: sorry - what does your table look like? If you have a \begin{table} then change it to \begin{table}[H} and see if that does it. If you don't have a \begin{table} , edit your question and add the LaTeX code for an example table - the contents don't matter but the structure does. – NickD Jan 20 at 13:08
• It was \begin{table}[], added H inside the square brackets. It worked! – abtoiew Jan 20 at 13:17
• Glad it worked! I'll edit the answer later to clarify. – NickD Jan 20 at 13:24

Try adding #+ATTR_LATEX: :placement [!h] as a header to the table. That says: Place the table here. The trouble with it is that if the table doesn't fit here, you'll end up with lots of blank space and the table on the next page.

Alternatively, \clearpage at the end of a section forces all floats (tables, figures) to be placed.

• I don't have anything but #+CAPTION:. I will try \clearpage. – abtoiew Jan 19 at 15:21
• It kind of worked but did not produce what I wanted. There's enough space under the heading but the table is for some reason on the next page. Take look at this image: link – abtoiew Jan 19 at 18:00
• I believe #CAPTION: turns the table into a float. If you eliminate the caption, the table should stay put. – NickD Jan 19 at 18:56
• I think the trouble with \clearpage` is that the page is cleared first and then the floats are forced out. – NickD Jan 19 at 20:51