1

I am quite new to latex, and am having some troubles in general with figure placementent. Take this as and example:

...

\section{First} Sample text: %\clearpage \begin{figure}[h!] \centering \caption{Sample caption} \label{fig:sample_1} \includegraphics[width=0.6\textwidth]{sample/1} \end{figure}

\section{Second} Some other text

...

Now, if I compile the tex document and the image is too big to fit in the current page, it is often added below the Second section. So then, I have to uncomment the \clearpage to break the current page (up to Sample text:) so that the image is added on a new page and the Second section after that.

This bothers me quite a lot. I would much rather waste some space and always insert the image on a new page, if it doesn't fit. Is it possible to do so?

The main problem is that if I add something above the code block above, then the \clearpage is used even if the image now fit, as Sample text: got moved on a new page by itself.

The strange thing to me is that I should be forcing the placement with [h!], but it still doesn't work..

  • Welcome to TeX.SE. – Mico Oct 03 '20 at 09:36
  • 4
    Does this answer your question? How do I ensure that figures appear in the section they're associated with?. Just load the placeins package with the option section in order to make sure that floats get placed before the next \section directive is executed. – Mico Oct 03 '20 at 09:38
  • The markup you are using directy works against your desired behaviour. \begin{figure}[h!] h (which almost always generates a warning, it should not be used on its own) h means not at top of page, (no t) not at bottom of page (no b) not on a page on its own (as forced by \clearpage) (no p). You should almost always include at least p and usually t and p if you use the optional argument. Also only use ! in exceptional cases (that is why ! is used as the character). – David Carlisle Oct 03 '20 at 10:15
  • Thanks a lot! The placeins is exactly what I needed. – bobicino Oct 03 '20 at 11:01

0 Answers0