0

The \clearpage macro outputs any remaining floats and then starts a new page.

I am after a command that outputs any remaining floats, does not start a new page and enables any following text to be put after the last float on the same page.

I have tried, to no avail,

% hprob.tex  SE 639516

\documentclass{memoir} \usepackage{lipsum} \usepackage{placeins} % provides \FloatBarrier \usepackage{comment}

%\show\clearpage

\makeatletter \newcommand{\flushfloats}{% A revision of \clearpage \ifvmode \ifnum @dbltopnum = \m@ne \ifdim \pagetotal <\topskip \hbox{} \fi \fi \fi % \newpage % \write \m@ne {} % \vbox {} % \penalty -@Mi% }

\makeatother

\begin{document} \chapter{First}

%Introductory text.

\begin{table} \centering A TABLE \caption{A table} \end{table}

\begin{table} \centering A TABLE \caption{A table} \end{table}

\begin{table} \centering A TABLE \caption{A table} \end{table}

\begin{table} \centering A TABLE \caption{A table} \end{table}

\begin{table} \centering A TABLE \caption{A table} \end{table}

\begin{table} \centering A TABLE \caption{A table} \end{table}

\begin{table} \centering A TABLE \caption{A table} \end{table}

%\clearpage \FloatBarrier \flushfloats

\lipsum[1]

\end{document}

My \flushfloats will output all the floats but then move on to the next page, which I do not want. It still acts like \clearpage.

Peter Wilson
  • 28,066
  • In general, you may not be able to fit all the floats in the queue (like full page floats or two column floats) onto the existing page. In fact, one should ask why they aren't already transferred to \@toplist or \@bottomlist. Anyway, the key here is \@deferlist. – John Kormylo Apr 05 '22 at 20:17

2 Answers2

2

If you force a float page with \clearpage you can not add text but here I think you want to go the other way and just allow more floats on a text page.

enter image description here

\documentclass{memoir}
\usepackage{lipsum}

\begin{document} \chapter{First}

%Introductory text.

\begin{table}[!hbp] \centering A TABLE \caption{A table} \end{table}

\begin{table}[!hbp] \centering A TABLE \caption{A table} \end{table}

\begin{table}[!hbp] \centering A TABLE \caption{A table} \end{table}

\begin{table}[!hbp] \centering A TABLE \caption{A table} \end{table}

\begin{table}[!hbp] \centering A TABLE \caption{A table} \end{table}

\begin{table}[!hbp] \centering A TABLE \caption{A table} \end{table}

\begin{table}[!hbp] \centering A TABLE \caption{A table} \end{table}

\lipsum[1]

\end{document}

[!h] was enough here but if you have an appendix or similar that just contains figures really you do not want them to float so a viable option is to use [H] from the float package so hey are all essentially text and following ext will naturally land on the same page.

David Carlisle
  • 757,742
  • The purpose behind my question was about not having to use [H] which I think causes more problems than it solves. Sorry, I prefer John Kormylo's answer which better fits the underlying (but unstated) reason behind my question. – Peter Wilson Apr 06 '22 at 17:31
  • @PeterWilson [H] (which was my idea originally) is pretty much always the wrong solution to any float probem, but I mentioned it here as a section of just a long series of floats that you don't want to float is pretty much the only time it has a reasonable use. But the main point of the answer here is not H but !h which allows as many floats as possible and allows text on the same page as the last float. – David Carlisle Apr 06 '22 at 18:01
  • I tried your !h recommendation which, unsurprisingly, worked. However I do not think that I will forward it to the original OP as he seemed to want a single placement argument throughout the document which would give him whatever placement he wanted at that particular point. --- GOM – Peter Wilson Apr 07 '22 at 18:12
1

Interestingly, it seems that adjusting totalnumber and \textfraction will not allow more than 4 floats per page. The only thing which works is [ht!].

\flushqueue copies and empties the entire \@deferlist, then goes through the copied list, separates figures from tables, and resubmits them as [ht!] floats.

\documentclass{memoir}
\usepackage{afterpage}
\usepackage{lipsum}

\makeatletter \newcommand*{\flushqueue}{\bgroup \let\mylist=@deferlist \gdef@deferlist{}\par \loop@next\mybox\mylist{}{\let\mybox=\voidb@x}% \ifvoid\mybox \else \ifnum\count\mybox<64 \begin{figure}[ht!] \unvbox\mybox \end{figure}\par \else \begin{table}[ht!] \unvbox\mybox \end{table}\par \fi \repeat \egroup} \makeatother

\begin{document} \chapter{First}

\begin{table}[t] \centering A TABLE \caption{A table} \end{table}

\begin{table}[b] \centering A TABLE \caption{A table} \end{table}

\begin{table}[p] \centering A TABLE \caption{A table} \end{table}

\begin{figure}[t] \centering A FIGURE \caption{A figure} \end{figure}

\begin{figure}[b] \centering A FIGURE \caption{A figure} \end{figure}

\begin{figure}[p] \centering A FIGURE \caption{A figure} \end{figure}

\flushqueue \lipsum[1]

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Thank you for your answer which was just what I was looking for. If you are interested in where my question came from see https://tex.stackexchange.com/questions/639516 – Peter Wilson Apr 06 '22 at 18:10
  • You could just use [ht!] if you want it to print immediately. I was thinking more along the lines of not needing it now, but definitely needing it before, say, starting a new section. – John Kormylo Apr 06 '22 at 19:00