2

I'm having some sections in a report with more images (figures) than text. I include the images in the following way:

\begin{figure}[h]
\centering
\resizebox{10cm}{!}{\includegraphics{images/test.png}}
\caption{Test image.}
\label{some label}
\end{figure}

The problem now is that some of the figures are shown in the next section.

How can I enfore the figures to be placed in the section where I'm including them (even if white space must be introduced)? Otherwise it gets very confusing for the reader.

I have tried to use \begin{figure}[H] but it did not help.

machinery
  • 694
  • Note that you are telling LaTeX: place this float here if there's room but, if not, push it to much later because I don't want it in the top float area and I don't want it in the bottom float area and I don't want you to put it on a page of floats. To use H you need to load the float package. – cfr Nov 07 '14 at 23:46
  • Use the placeins package. – Juri Robl Nov 07 '14 at 23:55
  • @cfr I don't think it's a duplicate really of Frank's answer, in particular that doesn't give the answer (which is to use placeins) – David Carlisle Nov 08 '14 at 00:19
  • note using [h] makes it inevitable that the floats go out of position, latex usually warns and changes it to [ht] it means not t, not b, not p, so prevents latex from placing the float more or less anywhere so makes it likely it gets held to the end. – David Carlisle Nov 08 '14 at 00:21
  • @DavidCarlisle But Roelof Spijker's answer there does. I didn't think that a question's answer had to be in the *accepted* answer of another question for it to count as a duplicate? – cfr Nov 08 '14 at 01:58
  • @cfr hmm possibly:-) – David Carlisle Nov 08 '14 at 09:06

2 Answers2

2

You can use the placeins package with the section option. If you want to relax the restrictions slightly, so that it's just on the same page as the section, you can use the additional options below and above. The package automatically inserts float barriers at each section.

Juri Robl
  • 4,763
  • Thanks. It works perfectly with placeins. I just have to insert \usepackage[section]{placeins} and now everything is fine. – machinery Nov 08 '14 at 14:51
0

The comprehensive approach is in the link in comments. However, if I properly understand your problem, a very simple solution is possible.

LaTeX \clearpage not only ends the current page, but also releases all the floats. The cost is, certainly, a page (sometimes pages) with free space. If it is acceptable for you, you can use this command before next section.