3

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 :

enter image description here

And :

enter image description here

\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):

  1. 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.

B Legrand
  • 521
  • How about \vskip-\intextskip when needed? Also, make sure \belowcaptionskip is 0pt (use \the\belowcaptionskip to print the value, or add \hrule below the caption inside the figure). – John Kormylo Feb 18 '24 at 21:07
  • @JohnKormylo Thank you, but I'm actually looking for an automatic solution rather than a manual one. It seems to me that \belowcaptionskip is equal to 0 pt for standard documentclasses (article and book). – B Legrand Feb 19 '24 at 11:47
  • I don't think an automatic solution is possible. figure has no way of knowing that it will wind up in front of a \section and \section has no way on knowing there is a figure iin front of it (remember, floats can move around). Besides, "too much space" is an aesthetic judgement (depends on the person). – John Kormylo Feb 19 '24 at 18:53
  • @JohnKormylo That's right, but if the vertical space \intextskip introduced 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 \intextskip and 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:40
  • 1
    The bad news is that \intextesp is added by \output, which is the most complex and tricky command in LaTeX. – John Kormylo Feb 20 '24 at 20:02
  • Note that using h means ht since LaTeX automatically substitutes the latter. Is ht the behaviour you actually want? – cfr Feb 21 '24 at 04:05
  • @cfr For this MWE I wanted to simplify things, but in reality in my documents I use \def\fps@figure{htbp}. – B Legrand Mar 01 '24 at 17:55

1 Answers1

0

I finally found a solution when I stumbled across this answer from Frank Mittelbach : https://tex.stackexchange.com/a/40363/209693.

This answer solves the problem raised in the LaTeX2e source document and mentioned in my question, but it also solves the main problem of my question.

B Legrand
  • 521