3

Am I missing something obvious, or is \captionof not supposed to work in a \makebox? I have tried \protect, \MakeRobustCommand, among others.

\documentclass{article}
\usepackage{capt-of}
\begin{document}
    \makebox{\captionof{figure}{X}}
\end{document}

I receive this error:

! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.4     \makebox{\captionof{figure}{X}}
7
  • Maybe helpful tex.stackexchange.com/a/222516/124842.
    – Bobyandbob
    Commented Apr 28, 2017 at 12:09
  • 2
    You can place it in a \parbox. Commented Apr 28, 2017 at 12:27
  • 1
    Yes you can. Though I wonder what added benefit wrapping the \parbox in a \makebox provides that the bare \parbox does not? Commented Apr 28, 2017 at 12:59
  • 1
    You might find \abovecaptionskip=0pt useful. Commented Apr 28, 2017 at 13:53
  • 1
    @StevenB.Segletes I use a hacky combination of three boxes, see tex.stackexchange.com/a/367225/30810. If that could be simplified, I would like that, but I haven't found shorter a solution yet.
    – bers
    Commented Apr 28, 2017 at 14:08

1 Answer 1

2

\makebox provides a horizontal box for content and therefore has difficulty coping with vertical content. In particular, \captionof eventually calls \@makecaption to set the actual caption. This starts and ends with vertical skips inserted via \vskip \abovecaptionskip and \vskip \belowcaptionskip. \vskips within a \makebox causes the problem:

\hrulefill

\mbox{\vspace{10pt}}% Acceptable...

\hrulefill

\mbox{\vskip 10pt}% Problematic...

\hrulefill

The above code snippet highlights the background legwork performed by \vspace in order to accommodate for non-vertical-mode skipping.

On the other hand, \parbox (and minipage, say) provide the option to incorporate horizontal and vertical content. So, if you want to place \captionof in a box, place it in a box that can manage its content, like a \parbox.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .