[Tex/LaTex] Ensure float appears directly after `\afterpage` and `landscape`

floatslandscapepage-breaking

I have a large (full page) landscape figure that I would like to appear on the page opposite to a large (full page) portrait figure. The landscape figure is generated like so:

\afterpage{
    \begin{landscape}
        \begin{figure}
            \centering
            \includegraphics[scale=1]{path/to/the/file.pdf}
            \caption{The Caption}
        \end{figure}
    \end{landscape}
}

The afterpage allows the landscape page to float around. I would now like to add a figure that is on the opposite page; I have done so currently by adding it into the landscape and rotating it:

\afterpage{
    \begin{landscape}
        \begin{figure}
            \centering
            \includegraphics[scale=1]{path/to/the/file.pdf}
            \caption{The Caption}
        \end{figure}

        \begin{figure}
            \centering
            \includegraphics[scale=1,angle=-90]{path/to/another/file.pdf}
            \caption{The Other Caption}
        \end{figure}
    \end{landscape}
}

This has a couple of problems with it, though – firstly, it doesn't ensure that they're on facing pages (only that they're on consecutive pages), and secondly it results in a rotated caption for the second figure, which is not ideal because it's really a portrait figure.

I have looked for a solution to this problem, but can't seem to find it. Can anyone suggest one, or point me in the right direction?

Best Answer

I'd just put the second figure after landscape rather than rotating it twice.

\afterpage{%
\clearpage
    \begin{landscape}
        \begin{figure}
            \centering
            \includegraphics[scale=1]{path/to/the/file.pdf}
            \caption{The Caption}
        \end{figure}
\end{landscape}
        \begin{figure}
            \centering
            \includegraphics{path/to/another/file.pdf}
            \caption{The Other Caption}
        \end{figure}
\clearpage
}

To check that it starts on an even page you should be able to do

\afterpage{\clearpage
\ifodd\value{page}
\afterpage{...}
\else
...
\fi
}

so it gets deferred again if it lands on an odd page.

Related Question