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..
placeinspackage with the optionsectionin order to make sure that floats get placed before the next\sectiondirective is executed. – Mico Oct 03 '20 at 09:38\begin{figure}[h!]h(which almost always generates a warning, it should not be used on its own)hmeans 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:15placeinsis exactly what I needed. – bobicino Oct 03 '20 at 11:01