Using some combination of the [htpb!]
options (or some other means I'm not aware of), is it possible to allow a floating figure to be placed immediately before the first reference in the text, rather than on the following page?
Consider an example:
\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}% MWE only
\usepackage{cleveref}
\begin{document}
\section{Lorem ipsum}
\lipsum[1-2]
\section{Results}
\lipsum[3]
Results are shown in \cref{fig:results}.
\begin{figure}[hbt]
\includegraphics{Figures/results}
\caption{Some results}
\label{fig:results}
\end{figure}
\lipsum[1-4]
\end{document}
For my "results" figure (a pdf, roughly 5cm square), this code will place it at the top of the following page. In this case, I would prefer that the figure be on the same page, just above the first reference in the text if necessary.
Is there combination of [htpb!]
that will use this order of preference for placing the float?
- Here
- At the bottom of this page
- Just before "Here"
- At the top of the next page
Number 3 seems to be the option that is missing. From my understanding of float behavior, LaTeX will always place the float between text paragraphs, meaning there should be space between \lipsum[3]
and the paragraph where I've referenced the figure. That space is the "just before" where I would like LaTeX to automatically place the figure when the next option would be the following page.
Without invoking the figure before the reference in the text, is there a way to have the figure appear before the text where it is invoked?
Here's what I want it to look like:
I accomplished this by moving the figure above the reference. I want to LaTeX to do that for me, but not all the time -- only when the next best option is the top of the next page.
[t]
option will place it on the same page as the reference is made. Else, one could manually invoke the figure with[ht]
option as its own paragraph, prior to the\cref
.t
option means exactly what you ask for (unless you are using theflafter
package. (It's almost always best to includep
as well)t
option does naturally allow it to appear before it is invoked as it can appear at the top of that page.