In floating environments such as the captions of figures, LaTeX has a \global\@minipagefalse, why is this necessary and what does this switch do?

  \sbox\@tempboxa{#1: #2}
  \ifdim \wd\@tempboxa >\hsize
    #1: #2\par
    \global \@minipagefalse

The @minipage switch is used by LaTeX to handle vertical spacing at the beginning of a minipage environment (or a similar construct). If it is true then \addvspace is not adding space. So if, for example, a minipage starts of with a list environment then the space normally added in front of the list (by \addvspace) is suppressed.

The switch will be set to true at the beginning of a minipage environment (or a similar construct) and is normally set to false by \everypar, i.e., the moment textual material appears in that "minipage".

Now in the case of the caption implementation, two different strategies are used: if the caption is wider than the current horizontal width, then it is re-set as a normal paragraph (so the switch would be set to false by \everypar). However is it is small then the box is used directly without triggering the paragraph builder. Therefore one has to set the switch manually in this case.

And the reason that it is done globally is just because the switch is always manipulated globally.


The sources say

The float mechanism, like minipage, sets the flag |@minipage| true
before executing the user-supplied text. Many \LaTeX\ constructs
test for this flag and do not add vertical space when it is true.
The intention is that this emulates \TeX's `top of page' behaviour.
The flag must be set false at the start of the first paragraph. This
is achieved by a redefinition of |\everypar|, but the call to
|\@parboxrestore| removes that redefinition, so it is re-inserted 
if needed. If the flag is already false then the |\caption| was not
the first entry in the float, and so some other paragraph has already
activated the special |\everypar|. In this case no further action is

The most important command that tests this switch is \addvspace which is the command that is mostly used to add the vertical space around display environments such as lists. It is a global flag and setting it in a float environment means the float acts in a consistent way even if it floats from somewhere where it is set to somewhere where it would not be set.

  • This much I could gather from the source2e, but shouldn't it then be outside the conditional? Why only at the hboxed caption? – Yiannis Lazarides Apr 29 '12 at 19:52
  • @YiannisLazarides Frank just answered the point about caption in his answer – David Carlisle Apr 29 '12 at 19:54
  • @Yiannis I think David's last part of the answer is a red herring. The switch takes care of itself and it only has to be set by \caption because of the caption implementation avoiding normal paragraphs. It is not doing a standardization which happens elsewhere. – Frank Mittelbach Apr 29 '12 at 19:59
  • Hmm if in doubt I'd believe @FrankMittelbach, rather than me:-) But I wasn't so much thinking about caption there, as arbitrary addvspace at the top of the float. If the switch wasn't set by the float addvspace would pick up whatever value was current at the point of the float, wouldn't it? Ah we are agreeing. I think. the start of the float is the "elsewhere" that Frank meant:-) – David Carlisle Apr 29 '12 at 20:04
  • indeed :-) the elsewhere is \@floatboxreset which sets the switch. And by the way if the caption is at the bottom of the float then it is correct if `\addvspace adds space. – Frank Mittelbach Apr 29 '12 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.