Rendered latex file’s pictures comes out after section that precedes it in the latex file

imagelatexpdf

So I have a Latex file with some plots. However there's a problem with the figure floats in the image. I have a picture right before a page break, and latex pushes the to big plot down to the next. Fine enough. But then it decides to go smart and push up the section after the plot, to the free space that was left when the picture was pushed down. The result is as you understand pretty confusing, if you are discussing plots.

Here is some code

\subsection{Part A2.1.6}
 The Xsi2-distrubution with h=40 and 1\% significance gives 63.7(22.2) which 
 is significantly smaller than both Ljung-Box applied to the linear and 
 quadratic residuals, from which we can conclude that the residuals are not iid, 
 and that the linear and quadratic models are not as good as wanted. 
\begin{figure}[h!]
\hspace*{-2.5cm}
    \centering
    \includegraphics[scale=0.40]{plot7_MEGAPLOT.png}
    \hspace*{-2.5cm}
    \vspace*{-0.5cm}
    \caption{Plot of raw and deseasonalized dat}
\end{figure} 
\\
\section{Part A2.2}
\subsection{Part A2.2.1}
The main qualitative difference between the plots/roots is that we have an 
converging oscillating function for the complex roots while the real values 
gives us a weakly oscillating converging function.

Best Answer

It sounds like you might need the placeins package to prevent floats crossing a section barrier.

I've summarised this and most of the other solutions for handling float placements here.

Related Topic