0

Is there some way to let Latex set the figure position together with inserting page breaks in order to have the image in close proximity to where it is referenced? I am writing a large document with multiple figures and when I place them using \usepackage{float} with [H], Latex inserts a lot of ugly large white spaces between paragraphs all through the document.

    \begin{figure}[H]
        \centering
        \includegraphics[width=\textwidth]{figures/example_fig.png};
    \caption{Example fig.}
    \label{fig:example}
    \end{figure}

When I instead of using [H] use [!htbp], as there are multiple figures, the figures are located in strange locations, far away from where they are referenced in the text.

I am wondering if there is some command to let Latex insert a few page breaks with instead of MANY large white spaces between paragraphs as with \usepackage{float} with [H].

I understand that the work around is to manually insert \newpage together with [H]. However, this implies a lot of manual work and many re-compilations.

Imran
  • 3,096
  • 2
    You could just stop using [H]. [ht] does the exact same thing most of the time but avoids creating large blank areas. – John Kormylo Sep 04 '22 at 14:05
  • 2
    Use simply \begin{figure}, ignore how they are placed and ignore also ugly spaces. Worry about this when the text is finished to avoid to spent lots of time for an optimization that is lost at the next change of text. – Ulrike Fischer Sep 04 '22 at 14:08
  • Do not use [H]. Fill that "ugly large white spaces" whit text mean inevitably move the floats, so place the floats in source text taking into account that the floats can float. On the other hand, sure that [htbp!] in *all* the floats produce big displacements? This the lest restrictive option, so or it is the minimum inevitable or you are doing something wrong, as being very restricitve in some float so it cannot be placed soon and this affect the positions of next floats too. – Fran Sep 04 '22 at 16:21
  • [H] is an explicit request to use ugly white space, only use it if you intend to move text by hand to get good page breaks. – David Carlisle Sep 04 '22 at 16:38
  • also do not routinely use ! it is useful in special cases to over-ride the constraints, but it makes no sense to set constraints to ensure good output then ignore them in all cases by using ! every time. – David Carlisle Sep 04 '22 at 16:43

1 Answers1

0

Check out the package called placeins. In the preamble, I used it the following way to make sure the figures stayed within each section:

\usepackage[section]{placeins}

In the main document, I would use it as:

    text text text
\FloatBarrier

\begin{figure}
        \centering
        \includegraphics[width=\textwidth]{figures/example_fig.png};
    \caption{Example fig.}
    \label{fig:example}
    \end{figure}

\FloatBarrier

text text text

Edit: Removed the [H]

  • sorry this makes no sense, \FloatBarrier as its name implies is for controlling floats, but \begin{figure}[H] is not a float. – David Carlisle Sep 04 '22 at 16:39
  • I should edit and remove the [H] from the code. I used to use \FloatBarrier before and after the figure to force the text and figure to stay where I wanted. That way, the white spacing would also go away. – Ginko-Mitten Sep 04 '22 at 20:39