[Tex/LaTex] After \clearpage move the figure to the top

floatspage-breaking

I need to make a "pagebreak" after a figure so I use \clearpage. But I want the figure to stay at the top of the page and not centering at the now empty page. My code right now looks like:

\begin{figure}[t]
    \centering
    \includegraphics[scale=0.5]{YY.PNG}
    \caption{XX}
    \label{fig:BB}
\end{figure}

\clearpage

\section{AAA}

Best Answer

You can use afterpage to perform some magic between page shipouts:

enter image description here

\documentclass{article}

\usepackage{graphicx,float}
\usepackage{afterpage}
\usepackage{showframe,lipsum}% Just for this example

\begin{document}

\section{First section}\lipsum[1-3]

\afterpage{
  \begin{figure}[H]
    \centering
    \includegraphics[width=.8\textwidth,height=.8\textheight]{example-image}
    \caption{XX}
  \end{figure}
  \clearpage
}

\clearpage% or more text (like \lipsum[4-6])

\section{Second section}\lipsum[4-6]

\end{document}

The image is stored in a non-float (using float's [H]ere float specifier) and output after the current page, together with a \clearpage. That ensure the figure appears on its own at the top between two pages of continuous content.

Related Question