The caption package^{∗}

Axel Sommerfeldt

                caption@sommerfeldt.net

2002/01/28

Abstract

The caption package was superseeded by the new caption2 package. So please use caption2 instead; for migrating please see the enclosed manual.

1 The code

1.1 Identification

1 \NeedsTeXFormat{LaTeX2e}[1994/06/01]
2 \ProvidesPackage{caption}[1995/04/05 v1.4b caption package (AS)]

1.2 Initial code

\captionfont \captionlabelfont \captionmargin  \captionsize is defined for backward compatibility with v1.3 of this package.
3 \newcommand{\captionsize}{}
4 \newcommand{\captionfont}{\captionsize}
5 \newcommand{\captionlabelfont}{}
6 \newlength{\captionmargin}

Here are the different basic types of captions implemented:

\as@normalcaption The ‘normal’ caption

7 \newcommand{\as@normalcaption}[2]{%
8 #1 #2\par}

\as@isucaption The ‘iso’ or ‘hang’ caption; this code was taken from The L^{A}TEX Companion[3, p155] and modified

9 \newcommand{\as@isucaption}[2]{%
10 \sbox{\as@captionbox}{#1\space}%
11 \addtolength{\as@captionwidth}{-\wd\as@captionbox}%
12 \usebox{\as@captionbox}\parbox[t]{\as@captionwidth}{\leavevmode#2}}

\as@centercaption The ‘center’ caption

13 \newcommand{\as@centercaption}[2]{%
14 \parbox[t]{\as@captionwidth}{{\centering#1 #2\par}}}

∗This package has version number 1.4b, last revised 1995/04/05.

\as@annecaption The ‘centerlast’ caption; the idea how to do this was taken from Brüggemann-Klein[4], it is also mentioned in Kopka[5, p227]

15 \newcommand{\as@annecaption}[2]{%
16 \addtolength{\leftskip}{0pt plus 1fil}%
17 \addtolength{\rightskip}{0pt plus -1fil}%
18 \setlength{\parfillskip}{0pt plus 2fil}%
19 #1 #2\par}

\as@shortcaption Short captions are centered by default

20 \let\as@shortcaption\as@centercaption

1.3 Detection of the subfigure package

\as@subcapsize \@thesubfigure \@thesubtable If the subfigure package is loaded, a little message will be typeout and \as@subcapsize – which sets the size of the subcaptions – will be defined. Also \@thesubfigure and \@thesubtable will be redefined here to support the \captionlabelfont in subcaptions, too (thanks to Kevin Ruland for this idea!). If you don’t like this behaviour, just load the caption package after the subfigure package (and eventually redefine the \subcapsize by yourself) or redefine \@thesubfigure and \@thesubtable after loading the caption package as shown in the documentation of the subfigure package.

21 \ifx\thesubfigure\undefined
22 \newcommand{\as@subcapsize}[1]{}
23 \else%
24 \typeout{\space\space\space\space\space\space\space\space\space
25  `subfigure' package detected}
26 \let\as@subcapsize\subcapsize
27 \renewcommand{\@thesubfigure}{{\captionlabelfont\thesubfigure}\space}
28 \renewcommand{\@thesubtable}{{\captionlabelfont\thesubtable}\space}
29 \fi

1.4 Declaration of options

There are four different types of captions supported: normal, isu, center and centerlast. hang is exactly the same as isu.

30 \DeclareOption{normal}{\let\as@caption\as@normalcaption}
31 \DeclareOption{isu}{\let\as@caption\as@isucaption}
32 \DeclareOption{hang}{\ExecuteOptions{isu}}
33 \DeclareOption{center}{\let\as@caption\as@centercaption}
34 \DeclareOption{anne}{\let\as@caption\as@annecaption}
35 \DeclareOption{centerlast}{\ExecuteOptions{anne}}

If option nooneline is set, only-one-line captions will behave like normal ones.

36 \DeclareOption{nooneline}{\AtBeginDocument{\let\as@shortcaption\as@caption}}

There are options for six different font sizes available, they also redefine the \subcapsize provided by the subfigure package (if detected).

37 \DeclareOption{scriptsize}{%
38 \renewcommand{\captionsize}{\scriptsize}
39 \as@subcapsize{\scriptsize}}
40 \DeclareOption{footnotesize}{%
41 \renewcommand{\captionsize}{\footnotesize}
42 \as@subcapsize{\scriptsize}}

43 \DeclareOption{small}{%
44 \renewcommand{\captionsize}{\small}
45 \as@subcapsize{\footnotesize}}
46 \DeclareOption{normalsize}{%
47 \renewcommand{\captionsize}{\normalsize}
48 \as@subcapsize{\footnotesize}}
49 \DeclareOption{large}{%
50 \renewcommand{\captionsize}{\large}
51 \as@subcapsize{\normalsize}}
52 \DeclareOption{Large}{%
53 \renewcommand{\captionsize}{\Large}
54 \as@subcapsize{\large}}

There are nine options available to set the font attributes of the caption labels.

55 \DeclareOption{up}{\renewcommand{\captionlabelfont}{\upshape}}
56 \DeclareOption{it}{\renewcommand{\captionlabelfont}{\itshape}}
57 \DeclareOption{sl}{\renewcommand{\captionlabelfont}{\slshape}}
58 \DeclareOption{sc}{\renewcommand{\captionlabelfont}{\scshape}}
59 \DeclareOption{md}{\renewcommand{\captionlabelfont}{\mdseries}}
60 \DeclareOption{bf}{\renewcommand{\captionlabelfont}{\bfseries}}
61 \DeclareOption{rm}{\renewcommand{\captionlabelfont}{\rmfamily}}
62 \DeclareOption{sf}{\renewcommand{\captionlabelfont}{\sffamily}}
63 \DeclareOption{tt}{\renewcommand{\captionlabelfont}{\ttfamily}}

If the option ruled is set, the captions of ruled floats provided by the float package will also be supported.

64 \DeclareOption{ruled}{\newcommand\as@ruled{}}

1.5 Execution of options

The ‘normal’ type of caption is preselected.

65 \ExecuteOptions{normal}
66 \ProcessOptions

1.6 Main code

\as@captionbox \as@captionwidth \as@makecaption \@makecaption And now . . . it’s . . . the new \@makecaption code!
67 \newsavebox{\as@captionbox}
68 \newlength{\as@captionwidth}
69 \newcommand{\as@makecaption}[2]{%
70 \setlength{\leftskip}{\captionmargin}%
71 \setlength{\rightskip}{\captionmargin}%
72 \addtolength{\as@captionwidth}{-2\captionmargin}%
73 \captionfont%
74 \sbox{\as@captionbox}{{\captionlabelfont #1:} #2}%
75 \ifdim \wd\as@captionbox >\as@captionwidth
76  \as@caption{{\captionlabelfont #1:}}{#2}%
77 \else%
78  \as@shortcaption{{\captionlabelfont #1:}}{#2}%
79 \fi}
80 \renewcommand{\@makecaption}[2]{%
81 \vskip\abovecaptionskip%
82 \setlength{\as@captionwidth}{\linewidth}%
83 \as@makecaption{#1}{#2}%

 84 \vskip\belowcaptionskip}

1.7 Support of the rotating package

\@makercaption \@makerotcaption If the rotating package is loaded, the command \@makerotcaption (for support of \rotcaption) will be redefined here. The code was taken from the rotating package [1] itself and adapted.

 85 \ifx\@makerotcaption\undefined
 86 \else
 87 \typeout{\space\space\space\space\space\space\space\space\space
 88  `rotating' package detected}
 89 % \let\@makercaption\undefined
 90 \renewcommand{\@makerotcaption}[2]{%
 91  \captionfont%
 92  \sbox{\as@captionbox}{{\captionlabelfont #1:} #2}%
 93  \ifdim \wd\as@captionbox > .8\vsize
 94  \rotatebox{90}{%
 95  \setlength{\as@captionwidth}{.8\textheight}%
 96  \begin{minipage}{\as@captionwidth}%
 97  \as@caption{{\captionlabelfont #1:}}{#2}%
 98  \end{minipage}}\par
 99  \else%
100  \rotatebox{90}{\usebox{\as@captionbox}}%
101  \fi
102  \hspace{12pt}}
103 \fi

1.8 Support of the float package

\floatc@plain \floatc@ruled If the float package is loaded, the command \floatc@plain (and the command \floatc@ruled if the option ruled is given) will be redefined here.

104 \ifx\floatc@plain\undefined
105 \else
106 \typeout{\space\space\space\space\space\space\space\space\space
107  `float' package detected}
108 \renewcommand\floatc@plain[2]{%
109  \setlength{\as@captionwidth}{\linewidth}%
110  \as@makecaption{#1}{#2}}
111 \ifx\as@ruled\undefined
112 \else
113  \renewcommand\floatc@ruled[2]{%
114  \setlength{\as@captionwidth}{\linewidth}%
115  \captionfont%
116  \as@caption{{\captionlabelfont #1:}}{#2}}
117 \fi
118 \fi

References

[1] Sebastian Rahtz and Leonor Barroca: A style option for rotated objects in L^{A}TEX, 1994/10/02 [2] Anselm Lingnau: An Improved Environment for Floats, 1995/03/25

[3] Michel Goossens, Frank Mittelbach and Alexander Samarin: The L^{A}TEX Companion, Addison-Wesley, Reading, Massachusetts, 1994.

[4] Anne Brüggemann-Klein: Einführung in die Dokumentverarbeitung, B.G. Teubner, Stuttgart, 1989

[5] Helmut Kopka: L^{A}TEX– Erweiterungsmöglichkeiten, 3. überarbeitete Auflage, Addison-Wesley, Bonn, 1991