latex

How do I control the width of a \caption{} in a float? (LaTeX)


I am looking for a simple way to control the width of a \caption{} inside a float in LaTeX without using the {caption} package. Any clues?

(EDIT): The problem I am having is that the built-in captions are too narrow.


Solution

  • To change the formatting of the standard LaTeX classes without using a package, you need to look at the source of the standard LaTeX classes and alter the original definitions in your own document. Printing captions is done by the macro \@makecaption, which has definition (in article.cls):

    \long\def\@makecaption#1#2{%
      \vskip\abovecaptionskip
      \sbox\@tempboxa{#1: #2}%
      \ifdim \wd\@tempboxa >\hsize
        #1: #2\par
      \else
        \global \@minipagefalse
        \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
      \fi
      \vskip\belowcaptionskip}
    

    If you wrap the whole thing in a minipage environment (as suggested to be done manually in the other answers), you should get the results you want.

    Is it easier than loading a package? Not really, but it can be instructive.