Let's assume that in a huge book of over 500 pages you often typeset long Notes (or other theorem-like environments) with Figures. You want that your Figures possibly stay near the declared places and that if a Figure floats at all, it floats within the Note logically containing it, i.e., between “Note ⟨note number⟩ ⟨(possibly, Note title in parens)⟩” and ■ terminating the Note. You also want that the floating and non-floating figures together maintain the same total order in the output as in the input. We could either nail the last figure of a Note with [H] and put a \FloatBarrier right before it (which makes the figure non-floating) or have the last figure floating but a halmos way too low:
\documentclass{svmono}% V5.10 from https://resource-cms.springernature.com/springer-cms/rest/v1/content/20566/data/monographs . For testing purposes, I hope, book would do as well.
\usepackage[latin,USenglish]{babel}%%% solely because lipsum is Latin
\usepackage{amssymb}
% \usepackage{float,afterpage}% also see \flushhere from http://tex.stackexchange.com/a/246315
\usepackage{placeins}
\usepackage{lipsum}
\makeatletter
% typesetting halmos:
\newlength\lastSkipOfEndCenter
\newcommand*{\halmosEndingNonProofAfterCenter}{\setlength\lastSkipOfEndCenter{\lastskip}\removelastskip\nopagebreak\par\nopagebreak\vspace{\dimexpr-\baselineskip-\parskip\relax}\nopagebreak{\unskip\nobreak\hfil\penalty50\hskip1em\null\nobreak\hfil\(\blacksquare\)\parfillskip=\z@\finalhyphendemerits=0\endgraf}\vskip\lastSkipOfEndCenter}
\makeatother
\begin{document}
\chapter{Chapter}
\newcommand{\figureheight}{19ex}% With ≤17ex, the halmos appears way too low below the figure. With 18 ex, the halmos appears of the next page. With ≥19 ex, Fig. 3 goes to the next page and the halmos appears way too low.
\lipsum[1]
\begin{figure}[htbp]\centering
\rule{10em}{\figureheight}
\caption{1}
\end{figure}
\lipsum[1]
\FloatBarrier
\begin{note}% Note 1
\lipsum[1]
\begin{figure}[htbp]\centering
\rule{10em}{\figureheight}
\caption{2}
\end{figure}
\lipsum[1]
%\FloatBarrier
\begin{figure}[htbp]\centering%%% We don't wish to simply use [H] for this figure and [h] elsewhere in the chapter because then the Figures might hypohetically come out in the wrong order. Otherwise, and with \FloatBarrier right before, [H] seems to do the job. Using [H] everywhere in the chapter is not an option because outside this environment, LaTeX does a good automatic job of placing the environment, and a manual placement everywhere would have to be reviewed too often.
\rule{10em}{\figureheight}
\caption{3}
\end{figure}%
\FloatBarrier
\halmosEndingNonProofAfterCenter
\end{note}
\lipsum[1]
\begin{figure}[htbp]\centering
\rule{10em}{\figureheight}
\caption{4}
\end{figure}
\lipsum[1]
\end{document}
Either of the two solutions probably preserves the order (though, as Skillmons explains in https://tex.stackexchange.com/a/654613, \FloatBarrier is not a panacea); feel free to correct me if I'm wrong. Is there any way to have the last Figure of the Note (in our example, Figure 3) floating (in our example, only above ■) such that the halmos is correctly placed on the last line of the Note, whether it is text or caption (in our example, of Figure 3)? Is there further any way to avoid the page break right before the halmos (to test, set \figureheight to 18ex)?
% typesetting halmos:why not the ams\qedhereand related commands? – David Carlisle Aug 20 '22 at 19:46{center}ed contents, and so on. Therefore, a single command\qedherewouldn't suit anyway. – Aug 20 '22 at 19:52\qedhere: I believe you. Still, we wish to have two different versions of\qedhere: one for q.e.d., the other for ■. Btw., I probably cannot useamsthm(it clashed withsvmonothe last time I tested it). – Aug 20 '22 at 19:58mathtools(i.e., internally,amsmath), but notamsthm. – Aug 20 '22 at 20:08\par\nobreakand applying a negative\vspaceto place the "halmos". Definitely required manual intervention. – barbara beeton Aug 20 '22 at 20:15\FloatBarrier\begin{figure}[H]\centering\begin{minipage}{\linewidth}\[…\]\par\nobreak\vspace{-\lastkip}■\end{minipage}\end{figure}? – Aug 20 '22 at 20:23Handh” in which the main text is being taken into consideration while placing a float or a halmos after the float or unindenting the first line of a para following a float :-). – Aug 20 '22 at 20:35\[ \begin{minipage} ... \end{minipage} \]\par\nobreak \vspace{-1.2\baselineskip}\leavevmode \hfill \halmos{\parfillskip=0pt \par} \par <text>. I'll take a look at your explicit example, but the important point is, not a float. – barbara beeton Aug 20 '22 at 22:11