For a particular application, I need to know whether or not a page contains a top float. I have therefore taken the definition of the conditional \iftopfloat{<true>}{<false>} given in the following link: Is there a way to determine if there is a float on a page?.
Initially, this conditional was used in document headers and footers. But in my case, I need to use it in the "body" of the document. However, the conditional doesn't work in this context and always executes the true branch regardless of the presence or absence of a top float.
How do you determine (from the document "body") whether or not there is a top float on a page?
\documentclass{article} \usepackage{mwe} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % From : https://tex.stackexchange.com/questions/56673/is-there-a-way-to-determine-if-there-is-a-float-on-a-page \makeatletter \let\latex@makecol\@makecol \def\@makecol{% \let\topfloat\@toplist% \latex@makecol% } \def\iftopfloat#1#2{\ifx\topfloat\empty #2\else #1\fi} \makeatother %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} \iftopfloat{Yes}{No} \clearpage \begin{figure}[t] \centering \includegraphics{example-image} \end{figure} \iftopfloat{Yes}{No} \clearpage\iftopfloat{Yes}{No} \clearpage \begin{figure}[t] \centering \includegraphics{example-image} \end{figure} \iftopfloat{Yes}{No} \clearpage \begin{figure}[t] \centering \includegraphics{example-image} \end{figure} \iftopfloat{Yes}{No} \clearpage\iftopfloat{Yes}{No} \clearpage\iftopfloat{Yes}{No} \end{document} 
\clearpage\iftopfloat{Yes}{No}after the clearpage there are no pending floats but you can not test at that point if later in the document there is afigurethat floats to the top of this page.\pdflastyposto see on the next run of latex if the first line is at the top of the page, and if not assume a float has been inserted and choose the correct code branch