Caption
Caption
1995/04/05
Abstract
The caption package provides many ways to customise the captions in
floating environments such figure and table. The \rotcaption command
and the sidewaysfigure and sidewaystable environments provided by the
rotating package from S. Rahtz and L. Barroca are also supported. The
caption package also cooperates with the float package written by A. Lingnau
and the subfigure package written by S.D. Cochran.
\usepackage[options]{caption}
in the preamble of your document, where the following options are supported:
\captionfont To setup the font size and attributes of the captions, this package also provides
\captionlabelfont ∗ This package has version number 1.4b, last revised 1995/04/05.
1
the commands \captionfont and \captionlabelfont to allow a more flexible
way to customize the captions than the above options could do. \captionfont is
called before each caption, \captionlabelfont is called just before the label of
the caption, so the whole caption will be created as
Note that these commands are used by the options, e.g. the options small and sf
are identical to
\renewcommand{\captionfont}{\small} and
\renewcommand{\captionlabelfont}{\sffamily} .
\captionmargin Furthermore there is a new length \captionmargin to setup an extra left and
right margin for the captions, e.g. the command
\setlength{\captionmargin}{10pt}
\usepackage{float,rotating,subfigure}
\usepackage[centerlast,small,sc]{caption}
The caption package now redefines the sidewaysfigure and sidewaystable envi-
ronments and the \rotcaption command provided by the rotating package from
S. Rahtz and L. Barroca. Note that the \captionmargin does not affect the
\rotcaption command.
It also redefines the captions of the plain and boxed styled floats provided by the
float package from A. Lingnau. ruled floats are not supported by default, but you
can change this via setting the option ruled. Note that the \captionmargin is
not supported in ruled floats.
If the subfigure package from S.D. Cochran is detected, the options scriptsize,
. . . , large will redefine \subcapsize in an adequate way. If you redefine
\captionfont by yourself and use the subfigure package, you also have to re-
define \subcapsize by yourself. Also the commands \@thesubfigure and
\@thesubtable will be redefined to use the \captionlabelfont command, please
take this into consideration if you redefine \@thesubfigure or \@thesubtable by
yourself. E.g. a adequate version of the second example in subfigure.sty will
be:
\renewcommand{\thesubfigure}{\thefigure.\arabic{subfigure}}
2
\makeatletter
\renewcommand{\@thesubfigure}{{\captionlabelfont\thesubfigure:}\space}
\renewcommand{\p@subfigure}{}
\makeatother
...
This package cooperates with the version 2.8 (1995/04/02) of the rotating package,
version 1.2c (1995/03/29) of the float package and version 1.6 (1993/05/13) of the
subfigure package, but will hopefully work with future versions, too.
2 Example
Here’s an example figure which was produced with the following code in the pream-
ble of this document:
\usepackage[hang,small,bf]{caption}
\setlength{\captionmargin}{20pt}
EXAMPLE FIGURE
Figure 1: This is an example caption with a small font and a sans serif label.
The hang option was used. There is a left and right margin of 20pt.
3 The code
3.1 Identification
1 \NeedsTeXFormat{LaTeX2e}[1994/06/01]
2 \ProvidesPackage{caption}[1995/04/05 v1.4b caption package (HS)]
3 \typeout{Package: caption v1.4b <1995/04/05> (Harald Sommerfeldt)}
\as@isucaption The ‘iso’ or ‘hang’ caption; this code was taken from The LATEX Companion[3,
p155] and modified
10 \newcommand{\as@isucaption}[2]{%
11 \sbox{\as@captionbox}{#1\space}%
3
12 \addtolength{\as@captionwidth}{-\wd\as@captionbox}%
13 \usebox{\as@captionbox}\parbox[t]{\as@captionwidth}{\leavevmode#2}}
\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]
16 \newcommand{\as@annecaption}[2]{%
17 \addtolength{\leftskip}{0pt plus 1fil}%
18 \addtolength{\rightskip}{0pt plus -1fil}%
19 \setlength{\parfillskip}{0pt plus 2fil}%
20 #1 #2\par}
If option nooneline is set, only-one-line captions will behave like normal ones.
37 \DeclareOption{nooneline}{\AtBeginDocument{\let\as@shortcaption\as@caption}}
4
There are options for six different font sizes available, they also redefine the
\subcapsize provided by the subfigure package (if detected).
38 \DeclareOption{scriptsize}{%
39 \renewcommand{\captionsize}{\scriptsize}
40 \as@subcapsize{\scriptsize}}
41 \DeclareOption{footnotesize}{%
42 \renewcommand{\captionsize}{\footnotesize}
43 \as@subcapsize{\scriptsize}}
44 \DeclareOption{small}{%
45 \renewcommand{\captionsize}{\small}
46 \as@subcapsize{\footnotesize}}
47 \DeclareOption{normalsize}{%
48 \renewcommand{\captionsize}{\normalsize}
49 \as@subcapsize{\footnotesize}}
50 \DeclareOption{large}{%
51 \renewcommand{\captionsize}{\large}
52 \as@subcapsize{\normalsize}}
53 \DeclareOption{Large}{%
54 \renewcommand{\captionsize}{\Large}
55 \as@subcapsize{\large}}
There are nine options available to set the font attributes of the caption labels.
56 \DeclareOption{up}{\renewcommand{\captionlabelfont}{\upshape}}
57 \DeclareOption{it}{\renewcommand{\captionlabelfont}{\itshape}}
58 \DeclareOption{sl}{\renewcommand{\captionlabelfont}{\slshape}}
59 \DeclareOption{sc}{\renewcommand{\captionlabelfont}{\scshape}}
60 \DeclareOption{md}{\renewcommand{\captionlabelfont}{\mdseries}}
61 \DeclareOption{bf}{\renewcommand{\captionlabelfont}{\bfseries}}
62 \DeclareOption{rm}{\renewcommand{\captionlabelfont}{\rmfamily}}
63 \DeclareOption{sf}{\renewcommand{\captionlabelfont}{\sffamily}}
64 \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.
65 \DeclareOption{ruled}{\newcommand\as@ruled{}}
5
76 \ifdim \wd\as@captionbox >\as@captionwidth
77 \as@caption{{\captionlabelfont #1:}}{#2}%
78 \else%
79 \as@shortcaption{{\captionlabelfont #1:}}{#2}%
80 \fi}
81 \renewcommand{\@makecaption}[2]{%
82 \vskip\abovecaptionskip%
83 \setlength{\as@captionwidth}{\linewidth}%
84 \as@makecaption{#1}{#2}%
85 \vskip\belowcaptionskip}
6
118 \fi
119 \fi
References
[1] Sebastian Rahtz and Leonor Barroca: A style option for rotated objects in
LATEX, 1994/10/02
[2] Anselm Lingnau: An Improved Environment for Floats, 1995/03/25
[3] Michel Goossens, Frank Mittelbach and Alexander Samarin: The LATEX Com-
panion, Addison-Wesley, Reading, Massachusetts, 1994.
[4] Anne Brüggemann-Klein: Einführung in die Dokumentverarbeitung, B.G.
Teubner, Stuttgart, 1989
[5] Helmut Kopka: LATEX– Erweiterungsmöglichkeiten, 3. überarbeitete Auflage,
Addison-Wesley, Bonn, 1991