2

I have noticed that table or figure is sometimes (I haven't figured the pattern yet) automatically placed before its reference, regardless of the code and [!h] (or [!ht]). Is it possible to turn this off? Better said, can I stop LaTeX playing with MY figures and tables (and do everything manually)?

Vochmelka
  • 965
  • 2
    This can be of interest: http://tex.stackexchange.com/a/39020/3954 . To answer your question, one option would be to use static objects (instead of floats) such as minipages and provide a caption using \captionof from the caption or capt-of packages. – Gonzalo Medina Feb 18 '14 at 00:16
  • 1
    Just expanding a little: tables and figures are meant to float. By using those environments, you are explicitly asking TeX to work out the best place to put them. That placement can be influenced but TeX will ultimately make the decision. If you don't want TeX to move them, don't use those environments. Use e.g. tabular or whatever instead. – cfr Feb 18 '14 at 00:38

1 Answers1

3

While using minipages or simply using \includegraphics and adding \caption using \captionof{figure}{Caption text} from either caption or capt-of package (both provide that macro) is a good idea, you can take shelter under the H position specifier of float package. [H] removes the floating nature of floats.

\documentclass{article}
\usepackage{graphicx,kantlipsum}
\usepackage{float}
\begin{document}
  Figure~\ref{fig:myfig} referred here.
  \kant[1-2]
  \begin{figure}[H]%[t]  %% change to [t] and see the difference
    \centering
    \includegraphics[width=4cm]{example-image-a}
    \caption{My figure}\label{fig:myfig}
  \end{figure}
  \kant

\end{document} 

enter image description here

As a side note there is flafter package that ensures the floats appear after they are first referred in text (to some extent). You have to add \usepackage{flafter} in your preamble.