# Force float to top of page selectively

Consider this example:

\documentclass{report}
%\usepackage{float}
\usepackage{lipsum}
\usepackage{graphicx}
\makeatletter
\setlength{\@fptop}{0pt}
\setlength{\@fpbot}{0pt plus 1fil}
\makeatother
\begin{document}
\lipsum[1-5]

\begin{figure}[htb]
\centering
\includegraphics[height=0.8\textheight, width=0.8\textwidth]{example-image-a}
\end{figure}

\begin{figure}[htb]
\centering
\includegraphics{example-image-c}
\end{figure}

\end{document}


The output is:

I have followed How to place a float at the top of a floats-only page? to force the "C" image to top of page. However, I do not want this setting to affect the "A" image. How can I force floats to top of page selectively?

At some point I would be interested to unset this setting for subsequent floats. I am checking @DavidCarlisle 's answer and trying to unset this setting using \clearpage:

\documentclass{report}
%\usepackage{float}
\usepackage{lipsum}
\usepackage{graphicx}

\begin{document}
\lipsum[1-5]

\begin{figure}[htbp]
\centering
\includegraphics[height=0.8\textheight, width=0.8\textwidth]{example-image-a}
\end{figure}
\clearpage
\makeatletter
\setlength{\@fptop}{0pt}
\setlength{\@fpbot}{0pt plus 1fil}
\makeatother

\begin{figure}[htbp]
\centering
\includegraphics{example-image-c}
\end{figure}
\clearpage

\begin{figure}[htbp]
\centering
\includegraphics{example-image-b}
\end{figure}

\end{document}


From the output it can be seen that I have been unsuccessful at unsetting the setting for the "B" image:

What is wrong?

• you are preventing float pages by omitting p from the optional argument so the figures can not be positioned at all, then finally at the end of the document they are all forced on to float pages via \clearpage as an emergency fix to stop them being lost. If you want them on float pages why use [htb] which is designed to prevent that? – David Carlisle Apr 20 at 19:55
• @DavidCarlisle, I observed that using p caused creation of pages for a single image. Instead I want my document to be more compact with text wrapping images. – Viesturs Apr 20 at 19:58
• You are specifying unachievable constraints so forcing all the floats to the end of the document. – David Carlisle Apr 20 at 20:00
• @DavidCarlisle I am more pleased with floats forced to the end rather than a float floating alone on an entire page. – Viesturs Apr 20 at 20:01
• But this entire question is about float pages that have just floats not text. – David Carlisle Apr 20 at 20:02

You can change \@fptop at any point to change the way float pages are set out, but all the pages handled by a single \clearpage will use the same layout. As you are using the optional argument to prevent any setting of the figures they are all going to the end and being forced by the implicit \clearpage at \end{document} so to use different setting, use \clearpage after the float A then set \@fptop to 0pt before float C is handled.

\documentclass{report}
%\usepackage{float}
\usepackage{lipsum}
\usepackage{graphicx}

\begin{document}
\lipsum[1-5]

\begin{figure}[tb]
\centering
\includegraphics[height=0.8\textheight, width=0.8\textwidth]{example-image-a}
\end{figure}
\clearpage
\makeatletter
\setlength{\@fptop}{0pt}
\setlength{\@fpbot}{0pt plus 1fil}
\makeatother

\begin{figure}[tb]
\centering
\includegraphics{example-image-c}
\end{figure}
\clearpage
\makeatletter
\setlength{\@fptop}{0pt plus 1fil}
\setlength{\@fpbot}{0pt plus 1fil}
\makeatother

\begin{figure}[tb]
\centering
\includegraphics{example-image-b}
\end{figure}

\end{document}


• How to unset this setting for following floats. A simple \clearpage does not work. – Viesturs Apr 23 at 8:17
• @Viesturs yes it does, the values current when the float page is shipped out will be used. – David Carlisle Apr 23 at 8:19
• I am unsuccessful at unsetting this setting. See an update to my question. – Viesturs Apr 23 at 8:31
• @Viesturs but in your update you never set the value of fp@top back, it is 0pt for the rest of the document. You need to set it back to fill of course. – David Carlisle Apr 23 at 8:41
• What is the syntax? I try \setlength{\@fptop}{fil} and get ! Missing number, treated as zero. <to be read again> f l.25 \setlength{\@fptop}{fil} – Viesturs Apr 23 at 8:47