When a section follows a float, the vertical space between the two elements is too large, as \intextsep is added to the spacing introduced by \section. Generally speaking, this is also true for other commands (such as \mycommand in the MWE below) that add vertical spacing. Consider the MWE and the following images as an example :
And :
\documentclass{book}
\usepackage{mwe, lipsum}
\makeatletter
\newcommand{\mycommand}{\par%
\vspace{16pt \@plus 4pt \@minus 2pt}%
{\centering\LARGE * * *\par}%
\vspace{16pt \@plus 4pt \@minus 2pt}%
\@afterindentfalse\@afterheading}
\makeatother
\begin{document}
\lipsum[1]
\begin{figure}[h]
\centering\includegraphics[width =.5\linewidth]{example-image}
\caption{Figure #1.}
\end{figure}
\mycommand\lipsum[2]
\mycommand\lipsum[2]
\newpage\lipsum[2]
\begin{figure}[h]
\centering\includegraphics[width =.5\linewidth]{example-image}
\caption{Figure #2.}
\end{figure}
\section{My section}\lipsum[2]
\section{My section}\lipsum[2]
\end{document}
Of course, I don't want \intextsep to equal 0 when the float is followed by text. So I can't simply write \setlength{\intextsep}{0pt}.
So I tried using \removelastskip or \addvspace{...} instead of \vspace{...} to compensate for the space added by \intextsep but to no avail...
Do you know how to make the vertical space of an \intextsep value placed at the top and bottom of a float behave like \addvspace so that the macro located after the float can use \addvspace, \removelastskip etc?
Interestingly, a similar problem is referenced in the LaTeX2e source document (page 1081 of the 2023-11-01 version):
- Two consecutive h floats are separated by twice \intextsep: this could be changed to one by use of \addvspace, OK? Note that it would also mean that less space is put in if an h float immediately follows other spaces. This is also possibly too big a change, at least for compatibility mode? Or it may be simply wrong! It has not been changed.
As suggested, I'd like to use floats using \addvspace (or at least similar behaviour). It's mentioned that this would be a big change, I don't know if that's to refer to the complexity of modifying the original code or to refer to the changes that would be found in the output documents and the resulting lack of backwards compatibility. Nevertheless, the commands for managing floats are far too complex for me and go far beyond my understanding of LaTeX. Naive use of \patchcmd{\@addtocurcol}{\skip\intextsep}{\addvspace{\intextsep}}{} did not, of course, solve the problem.


\vskip-\intextskipwhen needed? Also, make sure\belowcaptionskipis 0pt (use\the\belowcaptionskipto print the value, or add\hrulebelow the caption inside the figure). – John Kormylo Feb 18 '24 at 21:07\belowcaptionskipis equal to 0 pt for standard documentclasses (article and book). – B Legrand Feb 19 '24 at 11:47\intextskipintroduced before and after the float behaved like\addvspace, there's no need for the section to know that it's just after a float or vice versa. In this case, the vertical space between the float and the section (or other) would simply be the maximum between\intextskipand the vertical space created by the section (or other macro using\addvspace) instead of being the sum of the two spaces, generating large blanks on the page. I'll edit my post to clarify. – B Legrand Feb 20 '24 at 19:40hmeanshtsince LaTeX automatically substitutes the latter. Ishtthe behaviour you actually want? – cfr Feb 21 '24 at 04:05\def\fps@figure{htbp}. – B Legrand Mar 01 '24 at 17:55