[Tex/LaTex] Remove white space before landscape

floatslandscape

I am inserting a landscape figure.

\begin{landscape}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{figures/sensor_diffs.jpg}
\caption{Example of a single rep in which sensors are fused together to create a reaction time algorithm}
\label{fig:sensor_diffs}
\end{figure}

\begin{figure}
\centering
\includegraphics[width=\linewidth]{figures/sensor_diffs2.jpg}
\caption{Another example of a single rep in which sensors are fused together to create a reaction time algorithm}
\label{fig:sensor_diffs2}
\end{figure}
\end{landscape}

However, the page before the figure produces lots of white space at the end. There is plenty of text in same section after the figure, however it doesn't seem to be adjusting it properly.

Any ideas?

In addition, I have this issue in several places through the document so any sort of global solution would be ideal.

Best Answer

You can use afterpage package for this so that the figures are typeset after filling the current page.

\documentclass{article}
\usepackage{pdflscape}
\usepackage{graphicx}
\usepackage{afterpage}
\usepackage{lipsum}
\begin{document}
\lipsum[1-2]
\afterpage{%         <--------------like this
  \begin{landscape}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{example-image}
\caption{Example of a single rep in which sensors are fused together to create a reaction time algorithm}
\label{fig:sensor_diffs}
\end{figure}

\begin{figure}
\centering
\includegraphics[width=\linewidth]{example-image-a}
\caption{Another example of a single rep in which sensors are fused together to create a reaction time algorithm}
\label{fig:sensor_diffs2}
\end{figure}
\end{landscape}
}
\lipsum
\end{document}

enter image description here