2

How can we ensure that the spacing before or after a \vbox is correct when using \addvspace?

In the following MWE, the two \addvspace{10pt} which follow each other behave like two \vspace{10pt}. The vertical space is 20 pt whereas I would like it to be only 10 pt when using \addvspace.

\documentclass{article}

\usepackage{lipsum}

\begin{document} \newbox\testBox \setbox\testBox\vbox{\addvspace{10pt}\lipsum[1]}

\lipsum[2]\par \addvspace{10pt}

\unvbox\testBox

\clearpage

\setbox\testBox\vbox{\vspace{10pt}\lipsum[1]}

\lipsum[2] \vspace{10pt}

\unvbox\testBox \end{document}

B Legrand
  • 521
  • addvspace does its calculation at the time it is added it can't possibly survive being unboxed. Most likely the solution is to adjust things so you have not added the space to the top of the box, it's virtually impossible in classic tex to reliably tell what is at the start of a box. – David Carlisle Mar 03 '24 at 20:07
  • @DavidCarlisle Thank you for your reply. Unfortunately, I don't have much choice. The context of this question is as follows: I have a top float that introduces \textfloatsep followed immediately afterwards by a section or similar command that also introduces a vertical space using \addvspace. However, \addvspace doesn't work as expected (the maximum between the two vertical spaces is not taken). Searching through the LaTeX source code, I came across the \@cflt command. This MWE is intended to model the behavior of \@cflt in a simple way. – B Legrand Mar 06 '24 at 17:27
  • no that situation is completely different to the situation that you show here. If a float is being inserted at the top of a page it means a page break happened bfefore teh section, so the space added by addvspace above the section heading will have been discarded and all space added is under control of the macros in teh output routne. the problem that i commented on of not being able to see glue at teh top of a vbox does not occur in that case – David Carlisle Mar 06 '24 at 17:41
  • @DavidCarlisle OK, thank you for your clarification. If I understand correctly, I would need a \addvspace*{..} command which would be to \addvspace{..} what \vspace*{..} is to \vspace{..}? If so, I'll post a new question along these lines. – B Legrand Mar 06 '24 at 18:00
  • 1
    not really, addvspace looks up the currrent vertical list to see the space before, but there you know you are at the top of the page so you know there is no previous space, so just add whatever space you need, taking into account possible space at the bottom of the float box. – David Carlisle Mar 06 '24 at 18:27

0 Answers0