[Tex/LaTex] Sidewaysfigure can not place figure in the correct place

floatsrotating

I am using the sidewaysfigure command to place a large figure in a landscape position. However, I am not able to place the figures between the texts. All figures are displaced to the end of the PDF document.

Here is the mini-example:

\documentclass{article}
\usepackage{rotating}
\usepackage{float}
\usepackage{lipsum}

\begin{document}

\section{lipsum1}

\lipsum[1-4]

\begin{sidewaysfigure}[ht]
\centering
\noindent\includegraphics[scale=1]{example-image-a}\qquad
\caption{A.}
\label{fig_A}
\end{sidewaysfigure}

\section{lipsum2}
\lipsum

\begin{sidewaysfigure}[ht]
\centering
\noindent\includegraphics[scale=1]{example-image-b}\qquad
\caption{B.}
\label{fig_B}
\end{sidewaysfigure}

\end{document}

Best Answer

From the rotating documentation:

The package provides:

  • two new environments, sidewaystable and sidewaysfigure, each of which produces a single page-size float with contents rotated ±90 degrees; ...

So sidewaysfigure always inserts a full-page figure at the next possible pagebreak. As such, position arguments like [ht] don't make any sense here. In fact, [ht] seems to break the default behaviour such that the figures appear at the end of the document, and not at the next pagebreak after the current section.

Compiling your MWE just without the two occurences of [ht] results in the expected behaviour: The first figure on page 2, the second figure as last page of the document.

\documentclass{article}
\usepackage{rotating}
\usepackage{float}
\usepackage{lipsum}

\begin{document}

\section{lipsum1}

\lipsum[1-4]

\begin{sidewaysfigure}
\centering
\noindent\includegraphics[scale=1]{example-image-a}\qquad
\caption{A.}
\label{fig_A}
\end{sidewaysfigure}

\section{lipsum2}
\lipsum

\begin{sidewaysfigure}
\centering
\noindent\includegraphics[scale=1]{example-image-b}\qquad
\caption{B.}
\label{fig_B}
\end{sidewaysfigure}

\end{document}

enter image description here

Related Question