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%.
table
environment surrounding thetabular
. 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 atabular
which is not a floating environment: it will not move around.#+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)?#+LATEX_ATTR: :placement [!h]
. Did you try that? What went wrong?