The ccaption package^{∗}

Peter Wilson Catholic University of America

          Now at peter.r.wilson@boeing.com

1999/09/20

Abstract The ccaption package provides for ‘continuation’ captions, unnumbered

captions, and an ‘anonymous’ caption (a legend) that can be used in any environment. It also provides commands to define captions that can be used outside float environments. Further, it provides a mechanism for creating new types of float environments.

The package has been tested in conjunction with the rotating, caption2 and subfigure packages.

Contents

1 Introduction 2

2 The ccaption package 2 2.1 Use with the subfigure package . . . . . . . . . . . . . . . . . . . . 7 2.2 How L^{A}TEX makes captions . . . . . . . . . . . . . . . . . . . . . . 8

3 The package code 11 3.1 Continuation captions and legends . . . . . . . . . . . . . . . . . . 11 3.2 Non-float captions . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.3 New floats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.4 The subfigure20 option . . . . . . . . . . . . . . . . . . . . . . . . . 16

List of Tables

1 A multi-part table . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 Another table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 A legendary table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

A legendary table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

List of Figures

1 A picture is worth a thousand words . . . . . . . . . . . . . . . . . 10 2 A different kind of figure caption . . . . . . . . . . . . . . . . . . . 10

∗This file has version number v2.4, last revised 1999/09/20.

1 Introduction

Some publishers require that documents that include multi-part tables use a continuation caption on all but the first part of the multi-part table. For the times where such a table is specified by the author as a set of tables, the ccaption package provides a simple ‘continuation’ caption command to meet this requirement. It also provides a facility for an ‘anonymous’ caption which can be used in any float environment. The package has been tested with the rotating, caption2, and subfigure (v2.0) packages.

Captions can be defined that are suitable for use in non-float environments, such as placing a picture in a minipage and captioning it just as though it had been put into a normal figure environment. Further, a mechanism is provided for defining new float environments.

These facilities were originally developed in support of a suite for typesetting ISO international standard [Wil96], but they are generally applicable. This manual is typeset according to the conventions of the L^{A}TEX docstrip utility which enables the automatic extraction of the L^{A}TEX macro source files [GMS94].

Section 2 provides a short overview of the commands in the package and shows some examples of their use, while §2.2 gives examples of how L^{A}TEX’s captioning style can be changed without the use of any package. The implementation is given in Section 3.

2 The ccaption package

The package takes one option, namely subfigure20, for use in conjunction with version 2.0 of Steven Cochran’s subfigure package [Coc95].

The L^{A}TEX \caption command is used within either a table or a figure environment to produce appropriately labelled and numbered captions. The captioning text may also be listed via a \listoftables and/or \listoffigures command.

\contcaption The \contcaption{⟨text⟩} command can be used to put a ‘continuation’ or ‘concluded’ caption into a float environment. It neither increments the float number nor makes any entry into a float listing, but it does repeat the numbering of the previous \caption command.

Table 1 illustrates the use of the \contcaption command. The table was produced from the following code.

   \begin{table}
   \centering
   \caption{A multi-part table} \label{tab:m}
   \begin{tabular}{lc} \hline
    just a single line & 1 \\ \hline
   \end{tabular}
   \end{table}
   \begin{table}
   \centering
   \contcaption{Continued}
   \begin{tabular}{lc} \hline
    just a single line & 2 \\ \hline
   \end{tabular}

Table 1: A multi-part table

just a single line 1

Table 1: Continued

just a single line 2

   \end{table}
   \begin{table}
   \centering
   \contcaption{Concluded}
   \begin{tabular}{lc} \hline
    just a single line & 3 \\ \hline
   \end{tabular}
   \end{table}

\legend The \legend{⟨text⟩} command can be used to put an anonymous caption into

a float environment.

For example, the following code was used to produce the two-line table 2. The \legend command can be used within a float independently of any \caption command.

   \begin{table}
   \centering
   \caption{Another table} \label{tab:legend}
   \begin{tabular}{lc} \hline
    A legendary table & 5 \\
    with two lines    & 6 \\ \hline
   \end{tabular}
   \legend{The legend}
   \end{table}

Title legend

This is a marginal note with a legend.

Captioned floats are usually thought of in terms of the table and figure environments. There can be other kinds of float. As perhaps a more interesting example, the following code produces the titled marginal note which should be displayed near here.

     \marginpar{\legend{Title legend}
                This is a marginal note with a legend.}

You can even

Legend in running text

Table 1: Concluded

just a single line 3

Table 2: Another table

A legendary table 5
with two lines  6

The legend

Table A legendary table

An unnumbered table 5
with two lines  6

use the \legend command in running text, as has been done in this sentence, but I’m not sure why one might want to do that as L^{A}TEX already provides the center environment.

\formatlegend The macro \formatlegend{⟨text⟩} is responsible for specifying how the ⟨text⟩ of a \legend is to be typeset. The \legend command can be used to make unnumbered captions in a figure or table environment. For example, in a table environment you could do something like:

 \begin{table}
 ...
 \renewcommand{\formatlegend}[1]{\tablename: #1}
 ...
 \end{table}

In addition, if you wanted the title text to be included in the List of Tables, use the \addcontentsline command in conjunction with the \legend. For example:

 \addcontentsline{lot}{table}{Titling text} % left justifified
 \addcontentsline{lot}{table}{\protect\numberline{}Titling text} % indented

The first of these forms will align the first line of the titling text under the normal table numbers. The second form will align the first line of the titling text under the normal table titles. In either case, second and later lines of a multi-line title will be aligned under the normal title lines.

As an example, the last table is produced by the following code:

   \begin{table}
   \centering
   \renewcommand{\formatlegend}[1]{\textbf{\tablename} #1}
   \legend{A legendary table}
   \addcontentsline{lot}{table}{A legendary table}
   \addcontentsline{lot}{table}{\protect\numberline{}A legendary table}
   \begin{tabular}{lc} \hline
    An unnumbered table & 5 \\
    with two lines    & 6 \\ \hline
   \end{tabular}
   \end{table}

Look at the List of Tables to see how the two forms of \addcontentsline are typeset.

\abovelegendskip  Correspondingly to the \abovecaptionskip and \belowcaptionskip com-

\belowlegendskip mands associated with the \caption command, the spacing before and after a legend is controlled by the \abovelegendskip and \belowlegendskip commands. If necessary, these can be modified via the \setlength command. By default these are defined to give a half baseline spacing before and after the legend.

\namedlegend As a convenience, the \namedlegend[⟨short-title⟩]{⟨long-title⟩} command is like the \caption command except that it does not number the caption and, by default, puts no entry into a listof file. Like the \caption command, it picks up the name to be prepended to the title text from the float environment in which it is called (e.g., it uses \tablename if called within a table environment).

The two examples of tables below are equivalent:

 \begin{table}
 \renewcommand{\formatlegend}[1]{\tablename: #1}
 \legend{Long title text}
 ...
 \end{table}
 \begin{table}
 \namedlegend[Short title text]{Long title text}
 ...
 \end{table}

\flegtoc@type The macro \flegtoc@type{⟨title⟩}, where type is the name of a float environment (e.g., table) is called by the \namedlegend macro. It is provided as a hook that can be used to add ⟨title⟩ to the listof file. By default it is defined to do nothing, and can be changed via \renewcommand. For instance, it could be changed for tables as:

 \makeatletter
 \renewcommand{\flegtoc@table}[1]{%
   \addcontentsline{lot}{table}{#1}}
 \makeatother

\newfixedcaption The \legend command produces a plain, unnumbered heading. It can also

\renewfixedcaption
\providefixedcaption

be useful sometimes to have named and numbered captions outside a floating environment, perhaps in a minipage if you want the table or picture to appear at a precise location in your document.

The \newfixedcaption[⟨capcommand⟩]{⟨command⟩}{⟨env⟩} command, and its friends, can be used to create a new captioning ⟨command⟩ that may be used outside the float environment ⟨env⟩. Both the environment ⟨env⟩ and a captioning command, ⟨capcommand⟩, for that environment must have been defined before calling \newfixedcaption. Note that \namedlegend can be used as ⟨capcommand⟩.

   The \renewfixedcaption and \providefixedcaption commands take the

same arguments as \newfixedcaption; the three commands are analagous to those in the \newcommand family.

For example, to define a new \figcaption command for captioning pictures outside the figure environment, do

\newfixedcaption{\figcaption}{figure}

The optional ⟨capcommand⟩ argument is the name of the float captioning command that is being aliased. It defaults to \caption. As another example, where the optional argument is required, if you want to create a new continuation caption command for non-floating tables, say \ctabcaption, then do

\newfixedcaption[\contcaption]{\ctabcaption}{table}

Captioning commands created by \newfixedcaption will be named and numbered in the same style as the original ⟨capcommand⟩, can be given a \label, and will appear in the appropriate List of …. They can also be used within floating environments, but will not use the environment name as a guide to the caption name or entry into the List of …. For example, using \ctabcaption in a figure environment will still produce a Table… named caption.

These commands have been tested with the caption2 and rotating packages. They will most likely fail if used with the float package because of the way this package redefines the basic \caption command.

The float package, developed by Anselm Lingnau [Lin95], provides a simple scheme for creating new kinds of floats with a variety of captioning styles. Unfortunately the package does not effectively seperate the float creation aspects and the captioning styles. I have therefore included in the ccaption package a poor man’s version of some aspects of the float creation elements that are in float. Both the commands and their coding differ from those in the float package.

\newfloatenv The command \newfloatenv[⟨within⟩]{⟨fenv⟩}{⟨ext⟩}{⟨capname⟩} creates a new kind of floating environment called ⟨fenv⟩. A caption within the environment will be written out to a file with extension ⟨ext⟩. The caption, if present, will start with ⟨capname⟩. For example, if this command had been used to create the figure environment for the article class it would have been used as (remembering that L^{A}TEX uses \figurename to store the ‘Figure’ text):

\newfloatenv{figure}{lof}{\figurename}

The optional ⟨within⟩ argument can be used if you want the captions to be numbered within a particular document division, as figures are within the book and report classes with the numbering starting afresh with each new chapter. Creating the figure environment for either of these classes would have used:

\newfloatenv[chapter]{figure}{lof}{\figurename}

The captioning style for floats defined with \newfloatenv is the same as for figures and tables in the standard classes.

\listfloats The \listfloats{⟨fenv⟩}{⟨heading⟩} command can be used to typeset a listing of the float captions for the float environment ⟨fenv⟩. The listing will be preceeded by ⟨heading⟩ which will be in the same style as the headings for \listoftables and \listoffigures. So, just to finish off the figure example, instead of putting \listoffigures where you want the listing to appear, you would have had to use (remembering that L^{A}TEX uses \listfigurename to store the ‘List of Figures’ text)

\listfloats{figure}{\listfigurename}

As a fuller example, suppose you wanted both figures (which come with the standard classes), and diagrams. You could then do something like the following.

 \usepackage{ccaption}
 ...
 \newfloatenv{diagram}{dgm}{Diagram}
 \newfixedcaption{\fdiagcaption}{diagram}

 \begin{document}
 ...
 \listoffigures
 \listfloats{diagram}{List of diagrams}
 ...
 \begin{diagram}
 \caption{A diagram} \label{diag1}
 ...
 \end{diagram}
 As diagram~\ref{diag1} shows ...
 \begin{minipage}{.9\textwidth}
 \fdiagcaption{Another diagram} \label{diag2}
 ...
 \end{minipage}
 In contrast to diagram~\ref{diag1}, diagram~\ref{diag2} provides ...

As a matter of style, though, it would be more in keeping with L^{A}TEX to use the following for diagrams:

 ...
 \newcommand{\diagramname}{Diagram}
 \newcommand{\listdiagramname}{List of Diagrams}
 \newfloatenv{diagram}{dgm}{\diagramname}
 ...
 \listfloats{diagram}{\listdiagramname}
 ...

As a word of warning, if you mix both floats and fixed environments with the same kind of caption you have to ensure that they get printed in the correct order in the final document. If you do not do this, then the \list... of captions will come out in the wrong order (the lists are ordered according the page number in the typest document, not your source input order).

2.1 Use with the subfigure package

The subfigure package enables the captioning of sub-figures within a larger figure, and similarly for tables. If a figure that includes sub-figures is itself continued then it may be desireable to continue the captioning of the sub-figures. For example, if Figure 3 has three sub-figures, say A, B and C, and Figure 3 is continued then the sub-figures in the continuation should be D, E, etc.

\contsubfigure The command \contsubfigure[⟨subcaption⟩]{⟨figure⟩} will continue the sub- \contsubtable figure numbering scheme across (continued) figures. The \contsubtable com-

mand is similar but is intended for sub-tables.

\subconcluded The \subconcluded command is used to indicate that the continued subfigures or sub-tables have been concluded and the numbering scheme is reinitialized. The command should be placed immediately before the end of the last continued environment.

For example:

 \begin{figure}
 \subfigure{...} % captioned as (a)

 \subfigure{...} % captioned as (b)
 \caption{...}
 \end{figure}
 \begin{figure}
 \contsubfigure{...} % captioned as (c)
 \contsubfigure{...} % captioned as (d)
 \contcaption{Concluded}
 \subconcluded
 \end{figure}
 ...
 \begin{figure}
 \subfigure{...} % captioned as (a)
 \subfigure{...} % captioned as (b)
 \caption{...}
 \end{figure}

\subbottom Version 2.0 of the subfigure package assumes that the figure or table caption

\contsubbottom
\subtop
\contsubtop

comes at the end of the figure or table environment.

The ccaption package provides the commands \subbottom[⟨subcaption⟩]{⟨text⟩} and \contsubbottom[⟨subcaption⟩]{⟨text⟩} for the cases when the normal \caption or \contcaption commands are placed at the end of the float environment, and the similar \subtop and \contsubtop commands for when the main caption is at the start of the float environment. Actually the ccaption package \subfigure and \contsubfigure commands are aliases for the \...bottom commands, and likewise the \...table commands are aliases for the \...top commands.

2.2 How L^{A}TEX makes captions

This section provides an overview of how L^{A}TEX creates captions and gives some examples of how to change the captioning style without having to use any package. The section need not be looked at more than once unless you like reading L^{A}TEX code or you want to make changes to L^{A}TEX’s style of captioning.

The L^{A}TEX kernel provides tools to help in the definition of captions, but it is the particular class that decides on their format.

\caption The kernel (in ltfloat.dtx) defines the caption command via

\def\caption{\refstepcounter\@captype \@dblarg{\@caption\@captype}}

\@captype \@captype is defined by the code that creates a new float environment and is set to the environment’s name (see the code for \@xfloat in ltfloat.dtx). For a figure environment, there is an equivalent to

\def\@captype{figure}.

\@caption The kernel also provides the \@caption{⟨type⟩}[⟨short-title⟩]{⟨full-title⟩} command as:

 \long\def\@caption#1[#2]#3{%
   \par
   \addcontentsline{\csname ext@#1\endcsname}{#1}%    <----
     {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
   \begingroup
      \@parboxrestore
      \if@minipage
        \@setminipage
      \fi

      \normalsize
      \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par % <----
   \endgroup}

where ⟨type⟩ is the name of the environment in which the caption will be used. Putting these three commands together results in the user’s view of the caption command as \caption[⟨short-title⟩]{⟨full-title⟩}.

It is the responsibilty of the class (or package) which defines floats to provide definitions for \ext@type, \fnum@type and \@makecaption which appear in the definition of \@caption (in the lines marked <---- above).

\ext@type This macro holds the name of the extension for a ‘List of… ’ file. For example for the figure float environment there is the definition equivalent to

\newcommand{\ext@figure}{lof}.

\fnum@type This macro is responsible for typesetting the caption number. For example, for the figure environment there is the definition equivalent to

\newcommand{\fnum@figure}{\figurename~\thefigure}.

\@makecaption The \@makecaption{⟨number⟩}{⟨text⟩}, where ⟨number⟩ is a string such as ‘Table 5.3’ and ⟨text⟩ is the caption text, performs the typesetting of the caption, and is defined in the standard classes (in classes.dtx) as the equivalent of:

 \newcommand{\@makecaption}[2]{%
   \vskip\abovecaptionskip       %  <- 1
   \sbox\@tempboxa{#1: #2}%      %  <- 2
   \ifdim \wd\@tempboxa >\hsize
     #1: #2\par                  %  <- 3
   \else
     \global \@minipagefalse
     \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
   \fi
   \vskip\belowcaptionskip}      %  <- 4

\abovecaptionskip Vertical space is added before and after a caption (lines marked 1 and 4 in the \belowcaptionskip code for \@makecaption above) and the amount of space is given by the lengths

\abovecaptionskip and \belowcaptionskip. The standard classes set these to

10pt and 0pt respectively. If you want to change the space before or after a caption, use \setlength to change the values.

The actual typesetting of a caption is effectively performed by the code in lines marked 2 and 3 in the code for \@makecaption. If you want to make complex changes to the default captioning style you may have to create your own version of \@caption using \renewcommand. On the other hand, many such changes can be achieved by changing the definition of the the appropriate \fnum@type command(s). For example:

\renewcommand{\fnum@figure}{\textbf{\figurename~\thefigure}}

REMEMBER: If you are doing anything involving commands that include the @ character, and it’s not in a class or package file, you have to do it within a

\makeatletter and \makeatother pairing. So, if you modify the \fnum@figure

command anywhere in your document it has to be done as:

 \makeatletter
 \renewcommand{\fnum@figure}{......}
 \makeatother

A THOUSAND WORDS…

Figure 1: A picture is worth a thousand words

ANOTHER THOUSAND WORDS…

Figure 2 — A different kind of figure caption

As an example, Figure 1 was created by the following code:

 \makeatletter
 \renewcommand{\fnum@figure}{\textsc{\figurename~\thefigure}}
 \makeatother
 \begin{figure}
 \centering
 A THOUSAND WORDS\ldots
 \caption{A picture is worth a thousand words}\label{fig:sc}
 \end{figure}

As another example, suppose that you needed to typeset the \figurename and its number in a bold font, replace the colon that normally appears after the number by a long dash, and typeset the actual title text in a sans-serif font, as is illustrated by the caption for Figure 2. The following code does this.

 \makeatletter
 \renewcommand{\fnum@figure}[1]{\textbf{\figurename~\thefigure} --- \sffamily}
 \makeatother
 \begin{figure}
  \centering
  ANOTHER THOUSAND WORDS\ldots
 \caption{A different kind of figure caption}\label{fig:sf}
 \end{figure}

Perhaps a little description of how this works is in order. Doing a little bit of TEX’s macro processing by hand, the typesetting lines in \@makecaption (lines 2 and 3) get instantiated like:

\fnum@figure{\figurename~\thefigure}: text

Redefining \fnum@figure to take one argument and then not using the value of the argument essentially gobbles up the colon. Using

\textbf{\figurename~\thefigure}

in the definition causes \figurename and the number to be typeset in a bold font. After this comes the long dash. Finally, putting \sffamily at the end of the redefinition causes any following text (i.e., the actual title) to be typeset using the sans-serif font.

If you do modify \@makecaption, then spaces in the definition may be important; also you must use the comment (%) character in the same places as I have done above.

You may also want to take a look at the caption2 package by Harald Axel Sommerfeldt which provides a ready-made set of differing captioning styles. This basically works by redefining the \@makecaption command to provide some hooks. As the captions made by the ccaption package use \@makecaption they should match any style that you pick from caption2.

In the article class and its derivatives, captions are numbered continuously throughout the document, while in the book and report classes, numbering starts anew in each chapter.

If you want captions to be numbered anew with sections in the article class you can do this:

 \makeatletter
 \@addtoreset{table}{section}
 \renewcommand{\thetable}{\thesection.\arabic{table}}
 \makeatletter

and similarly for all the other float environments.

If you are using the book or report class and you want the captions to be numbered consecutively throughout the document you can do this:

 \makeatletter
 \@removefromreset{table}{chapter}
 \renewcommand{\thetable}{\arabic{table}}
 \makeatother

and similarly for all the other float environments. Note that you will need the remreset package^{1} which provides the definition of \@removefromreset.

3 The package code

Announce the name and version of the package, which requires L^{A}TEX 2ε.

1 ⟨∗usc⟩

 2 \NeedsTeXFormat{LaTeX2e}
 3 \ProvidesPackage{ccaption}[1999/09/20 v2.4 Extended captioning and new floats]

Do the option.

\if@contsubfigxx Used to remember if the subfigure20 option has been given.

 4 \newif\if@contsubfigxx
 5 \@contsubfigxxfalse
 6 \DeclareOption{subfigure20}{\@contsubfigxxtrue}
 7 \ProcessOptions

3.1 Continuation captions and legends

\contcaption \contcaption{⟨text⟩} is a user-level command. It is a simplified version of the normal \caption command as it doesn’t have to deal with numbering or list of … entries.

 8 \newcommand{\contcaption}{\@contcaption\@captype}

1Available on CTAN in tex-archive/macros/latex/contrib/supported/carlise.

\@contcaption This is the workhorse for the \contcaption command. In turn, it uses the \@makecaption command (defined in the usual classes) to do most of its work. It uses the number of the previous \caption command in the same type of float and its implementation includes much of the code used in the L^{A}TEX \@caption command.

 9 \long\def\@contcaption#1#2{%
10 \begingroup
11  \@parboxrestore
12  \if@minipage
13  \@setminipage
14  \fi
15  \normalsize
16  \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #2}\par
17 \endgroup}

\abovelegendskip \belowlegendskip These two lengths control the vertical spacing before and after a legend. We will give these values such that a legend will ocupy an integral number of lines.

18 \newlength{\abovelegendskip}
19 \setlength{\abovelegendskip}{0.5\baselineskip}
20 \newlength{\belowlegendskip}
21 \setlength{\belowlegendskip}{\abovelegendskip}

\legend The command is called as \legend{⟨text⟩}. It is intended to be used in a float

environment for an ‘anonymous’ caption.

The implementation is similar to the \caption command.

22 \newcommand{\legend}[1]{%
23 \par
24 \begingroup
25  \@parboxrestore
26  \if@minipage
27  \@setminipage
28  \fi
29  \normalsize
30  \@makelegend{}{\ignorespaces \formatlegend{#1}}\par
31 \endgroup}

\formatlegend \formatlegend{⟨text⟩} is resonsible for typesetting a legend’s text.

32 \newcommand{\formatlegend}[1]{#1}

\@makelegend The implementation of this command is similar to that of the \@makecaption command in the standard classes, or to the redefined version of \@makecaption if the caption2 package has been loaded.

33 \AtBeginDocument{%
34 \@ifpackageloaded{caption2}{%
35  \newcommand{\@makelegend}[2]{%
36  \vskip\abovelegendskip
37  \realcaptionwidth\linewidth
38  \def\captionlabel{#1}%
39  \def\captiontext{#2}%
40  \usecaptionstyle{\caption@style}%
41  \vskip\belowlegendskip}}{%
42  \newcommand{\@makelegend}[2]{%

43  \vskip\abovelegendskip
44  \sbox\@tempboxa{#1 #2}%
45  \ifdim \wd\@tempboxa >\hsize
46  #1 #2\par
47  \else
48  \global \@minipagefalse
49  \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
50  \fi
51  \vskip\belowlegendskip}}

52 }

\namedlegend \namedlegend[⟨short-title⟩]{⟨long-title⟩} is like the \caption command except that it does not number the caption.

53 \newcommand{\namedlegend}{\@dblarg{\@legend\@captype}}

\@legend \@legend{⟨type⟩}[⟨short-title⟩]{⟨long-title⟩} is the workhorse for the \namedlegend command. In turn, it calls \@makelegend. It requires two commands to have been defined, namely \flegtoc@type and \fleg@type. The command \flegtoc@type{⟨text⟩} is responsible for writing a title text to the appropriate listof file. \fleg@type is responsible for typeseting the name of the legend.

54 \long\def\@legend#1[#2]#3{%
55 \par
56 \csname flegtoc@#1\endcsname{#2}%
57 \begingroup
58  \@parboxrestore
59  \if@minipage
60  \@setminipage
61  \fi
62  \normalsize
63  \@makelegend{\csname fleg@#1\endcsname}{\formatlegend{#3}}\par
64 \endgroup}

\flegtoc@table \flegtoc@figure These macros write a \namedlegend title to the respective listof file. By default they do nothing.

65 \newcommand{\flegtoc@table}[1]{}
66 \newcommand{\flegtoc@figure}[1]{}

\fleg@table \fleg@figure These macros typeset the name before the title of a \namedlegend. By default they are defined to mimic the normal captioning style.

67 \newcommand{\fleg@table}{\tablename: }
68 \newcommand{\fleg@figure}{\figurename: }

3.2 Non-float captions

\newfixedcaption \renewfixedcaption \providefixedcaption These commands are defined in terms of their \...command counterparts.

Call as \...fixedcaption[⟨capcommand⟩]{⟨command⟩}{⟨env⟩}

69 \newcommand{\newfixedcaption}[3][\caption]{%
70 \newcommand{#2}{\def\@captype{#3}#1}}
71 \newcommand{\renewfixedcaption}[3][\caption]{%
72 \renewcommand{#2}{\def\@captype{#3}#1}}
73 \newcommand{\providefixedcaption}[3][\caption]{%
74 \providecommand{#2}{\def\@captype{#3}#1}}

3.3 New floats

To define a float environment, say fenv, the following macros must be defined:

• \fps@fenv The default placement specifier (normally tbp).

• \ftype@fenv The type number which is an integer and a power of 2.

• \ext@fenv The file extension for the contents list.

• \c@fenv A counter for the environment (for caption numbering).

• \fnum@fenv A macro to generate the caption ‘number’.

• \l@fenv A macro to produce an entry in a list of. …

• \flegtoc@fenv A macro to write a \namedlegend title to a listof file.

• \fleg@fenv A macro to typeset the name of a \namedlegend.

Note that the last two are only required for the ccaption package while the others are required for any new float, whether or not the ccaption package is being used.

newflo@tctr A counter for the type number of a new float. Normally figures are of type 1, tables type 2, and the next float type is then 4, and so on.

75 \newcounter{newflo@tctr}
76 \@ifundefined{c@figure}{\setcounter{newflo@tctr}{1}}{
77 \@ifundefined{c@table}{\setcounter{newflo@tctr}{2}}{
78  \setcounter{newflo@tctr}{4}}}

\newfloatenv The command \newfloatenv[⟨within⟩]{⟨fenv⟩}{⟨ext⟩}{⟨capname⟩} creates a new float environment called ⟨fenv⟩, with captions named ⟨capname⟩. Caption titles will be written to file \jobname.⟨ext⟩. ⟨within⟩ can be used for numbering within the document ⟨within⟩ division.

Start off by checking if this is not a new float, by testing the float counter. We can rely on the normal L^{A}TEX command/environment making code to handle the case when ⟨fenv⟩ has been defined previously.

79 \newcommand{\newfloatenv}[4][*]{%
80 \@ifundefined{c@#2}{%

It hasn’t been defined before, so check if numbering is going to be within a some other numbering scheme.

81  \def\opt@rg{#1}
82  \ifcat*\opt@rg
83  \newcounter{#2}
84  \else

We are numbering within, so check that there is a within counter.

85  \@ifundefined{c@#1}{\PackageWarning{ccaption}%
86  {#1 has no counter for use as a `within'}
87  \newcounter{#2}}%

There is a valid within counter. Do complicated things to define the \thefenv. With just \newcounter{#2}\the#2 is automatically set to arabic numbering. We

have to set it to \thewithin.\the#2.
88  {\newcounter{#2}[#1]%

 89  \expandafter\edef\csname the#2\endcsname{%
 90  \expandafter\noexpand\csname the#1\endcsname.\noexpand\arabic{#2}}}
 91  \fi

Next we set the type for the new float, using newflo@tctr, and doubling it afterwards.

 92  \@namedef{ftype@#2}{\value{newflo@tctr}} % float type
 93  \addtocounter{newflo@tctr}{\value{newflo@tctr}}

Having set up the counters, the rest is easy. We just define the commands that are needed for floats.

 94  \@namedef{fps@#2}{tbp}                   % default positioning
 95  \@namedef{ext@#2}{#3}                    % file extension
 96  \@namedef{fnum@#2}{#4~\@nameuse{the#2}}  % caption naming
 97  \@namedef{fleg@#2}{#4: }                 % named legend naming
 98  \@namedef{flegtoc@#2}##1{}                % legend title to listof

Define the macro that will format the entries. This is a straight copy from the book/article class code for figures (tables).

 99  \@namedef{l@#2}{\@dottedtocline{1}{1.5em}{2.3em}}%

Finally, define the new (starred) floating environment.

100  \newenvironment{#2}{\@float{#2}}{\end@float}
101  \newenvironment{#2*}{\@dblfloat{#2}}{\end@dblfloat}
102 }{%

Error handling for previously defined environment.

103  \PackageError{ccaption}{#2 has been previously defined}{\@eha}

104 } 105 }

\listfloats The \listfloats{⟨fenv⟩}{⟨heading⟩} command can be used to produce a list of floats for ⟨fenv⟩. The listing has title ⟨heading⟩. First check if there is a file extension for ⟨fenv⟩.

106 \newcommand{\listfloats}[2]{%
107 \@ifundefined{ext@#1}{\PackageError{ccaption}%
108  {File extension for #1 is undefined}{\@eha}}{%

Decide on the heading style. For classes with chapters this will be a \chapter* heading, otherwise a \section* heading. Copy the code from the book or article class as appropriate. Section style heading is easy.

109  \@ifundefined{chapter}{%
110  \section*{#2\@mkboth{\MakeUppercase{#2}}{\MakeUppercase{#2}}}}{%

Chapter style is more tedious.

111  \if@twocolumn
112  \@restonecoltrue\onecolumn
113  \else
114  \@restonecolfalse
115  \fi
116  \chapter*{#2\@mkboth{\MakeUppercase{#2}}{\MakeUppercase{#2}}}}%

And start reading the file.

117  \@starttoc{\@nameuse{ext@#1}}

At the end, if it was a \chapter* style heading we may have to restore twocolumn typesetting.

118  \@ifundefined{chapter}{}{\if@restonecol\twocolumn\fi}

119 }}

3.4 The subfigure20 option

In order to eliminate an ordering dependency between the subfigure and ccaption packages, modifications to the original subfigure code have to be done at the start of the document after all packages have been loaded.

120 \AtBeginDocument{%
121 \if@contsubfigxx

\@subcaption The original \@subcaption command produces unexpected results in the ToC (i.e., numberline appears instead of \numberline). I have also modified it so that when a top main caption is being used, it adds the subcaption to the ToC dfirectly.

122 \renewcommand{\@subcaption}[2]{%
123 \begingroup
124  \let\label\@gobble
125  \if@contbotsub
126 %%%      \def\protect{\string\string\string} % this was the problem
127  \xdef\@subfigcaptionlist{%
128  \@subfigcaptionlist,%
129 %%    {\protect\numberline {\@currentlabel}%
130  {\string\numberline {\@currentlabel}%
131  \noexpand{\ignorespaces #2}}}%
132  \else
133  \addcontentsline{\csname ext@#1\endcsname}{#1}%
134  {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
135  \gdef\@subfigcaptionlist{}
136  \fi
137 \endgroup
138 \@nameuse{@make#1caption}{\@nameuse{@the#1}}{#2}}

\subfigure \subtable These are revised versions of the original commands. They are now aliases for \subbottom and \subtop respectively. In their original form they were both effectively aliases for \subbottom only.

139 \let\subfigure\subbottom
140 \let\subtable\subtop

This is the end of \AtBeginDocument code.

141 \fi

142 }

\if@contbotsub A flag indicating whether the main caption is at the top or bottom of the float environment. For reasons that I don’t understand, the \newif cannot be within

an \if......\fi construct.
143 \newif\if@contbotsub
144 \@contbotsubtrue

Do the remaining code for the option, if called for.

145 \if@contsubfigxx

\@contkeep \@contset \subconcluded  \@contkeep stores the value of the sub-caption counter, and \@contset assigns

the stored value to the sub-caption counter. \subconcluded resets the sub-caption counter to zero, ready for a new non-continued float.

146 \newcounter{@contsubnum}
147 \newcommand{\@contkeep}{\setcounter{@contsubnum}{\value{sub\@captype}}}
148 \newcommand{\@contset}{\setcounter{sub\@captype}{\value{@contsubnum}}}
149 \newcommand{\subconcluded}{\setcounter{sub\@captype}{0}}

\subbottom \subbottom[⟨caption⟩]{⟨text⟩} typesets a subcaption when the main caption is at the end of the float environment. The code is a slight modification of the original \subfigure command in that the bottom flag is added and set to true and the subcaption number is stored.

150 \newcommand{\subbottom}{%
151 \@contbotsubtrue
152 \bgroup
153  \advance\csname c@\@captype\endcsname\@ne
154  \refstepcounter{sub\@captype}\@contkeep%
155  \leavevmode
156  \@ifnextchar [%
157  {\@subfloat{sub\@captype}}
158  {\@subfloat{sub\@captype}[\@empty]}}

\contsubbottom The continued version of \subbottom. It restores the kept subcaption number before incrementing and keeping it.

159 \newcommand{\contsubbottom}{%
160 \@contbotsubtrue
161 \bgroup
162 \@contset
163 \refstepcounter{sub\@captype}\@contkeep%
164 \leavevmode
165 \@ifnextchar [%
166  {\@subfloat{sub\@captype}}
167  {\@subfloat{sub\@captype}[\@empty]}}

\subtop \subtop[⟨caption⟩]{⟨text⟩} typesets a subcaption when the main caption is at the top of the float environment. This is new code and like the \subbottom code but the main caption number does not require incrementing.

168 \newcommand{\subtop}{%
169 \@contbotsubfalse
170 \bgroup
171  \refstepcounter{sub\@captype}\@contkeep%
172  \leavevmode
173  \@ifnextchar [%
174  {\@subfloat{sub\@captype}}
175  {\@subfloat{sub\@captype}[\@empty]}}

\contsubtop The continued version of \subtop. It restores the kept subcaption number before incrementing and keeping it.

176 \newcommand{\contsubtop}{%
177 \@contbotsubfalse
178 \bgroup
179 \@contset
180 \refstepcounter{sub\@captype}\@contkeep%

181 \leavevmode
182 \@ifnextchar [%
183  {\@subfloat{sub\@captype}}
184  {\@subfloat{sub\@captype}[\@empty]}}

\@contcaption The \@contcaption command must be modified to add the listed subcaptions (if any, and there should be none for top main captions) to the ToC.

185 \let\subfig@oldcontcaption\@contcaption
186 \long\def\@contcaption#1#2{%
187 \subfig@oldcontcaption{#1}{#2}%
188 \@for \@tempa:=\@subfigcaptionlist \do {%
189  \ifx\@empty\@tempa\relax \else
190  \addcontentsline
191  {\@nameuse{ext@sub#1}}%
192  {sub#1}%
193  {\@tempa}%
194  \fi}%
195 \gdef\@subfigcaptionlist{}}
\contsubtable \contsubfigure Aliases for \contsubtop and \contsubbottom, respectively.
196 \let\contsubtable\contsubtop
197 \let\contsubfigure\contsubbottom

The end of the subfigure20 option code.

198 \fi

The end of this package.

199 ⟨/usc⟩

References

[Coc95] Steven Douglas Cochran. The subfigure package. March 1995. (Available from CTAN as file subfigure.dtx)

[GMS94] Michel Goossens, Frank Mittelbach, and Alexander Samarin. The LaTeX Companion. Addison-Wesley Publishing Company, 1994.

[Lin95] Anselm Lingnau. An Improved Environment for Floats. March 1995. (Available from CTAN as file float.dtx)

[Wil96] Peter R. Wilson. LaTeX for standards: The LaTeX package files user manual. NIST Report NISTIR, June 1996.

Index

Numbers written in italic refer to the page where the corresponding entry is described, the ones underlined to the code line of the definition, the rest to the code lines where the entry is used.

Symbols

\@caption . . . . . . . . . 8 \@captype 8, 8, 53, 70, 72, 74, 147–149, 153, 154, 157, 158, 163, 166, 167, 171, 174, 175, 180, 183, 184

                                                   \@contbotsubfalse .

. . . . . . . . 169, 177

\@contbotsubtrue . .

…. 144, 151, 160

\@contcaption . 8, \underline{9}, \underline{185}
\@contkeep . . . \underline{146},

154, 163, 171, 180 \@contset . \underline{146}, 162, 179

\@contsubfigxxfalse . 5
\@contsubfigxxtrue . . 6
\@currentlabel 129, 130

\@dblarg . . . . . . . . . 53

\@dblfloat . . . . . . . 101
\@dottedtocline . . . 99

\@eha . . . . . . . . 103, 108 \@for . . . . . . . . . . . . 188

\@ifnextchar . . . . . .

. 156, 165, 173, 182

\@ifpackageloaded . 34
\@ifundefined 76, 77,

80, 85, 107, 109, 118 \@legend . . . . . . . 53, \underline{54}

\@makecaption . . . . 8, 16
\@makelegend . 30, \underline{33}, 63
\@minipagefalse . . . 48

\@namedef … 92, 94–99

\@nameuse . . . . . . . .

. 96, 117, 138, 191

\@parboxrestore . . .

. . . . . . . 11, 25, 58

\@restonecolfalse . 114
\@restonecoltrue . . 112
\@setminipage 13, 27, 60
\@starttoc . . . . . . . 117
\@subcaption . . . . . . \underline{122}
\@subfigcaptionlist

. . . . . . . . 127, 128, 135, 188, 195

\@subfloat . . . 157,

158, 166, 167, 174, 175, 183, 184

\@tempa … 188, 189, 193

A

\abovecaptionskip . . 9
\abovelegendskip . .

. . . . . 4, \underline{18}, 36, 43

\addcontentsline . .

. . . . . . . . 133, 190

\addtocounter . . . . . 93
\AtBeginDocument 33, 120

B

\baselineskip . . . . . 19
\belowcaptionskip . . 9

                          \belowlegendskip . .

. . . . . 4, \underline{18}, 41, 51

C \caption . . 8, 69, 71, 73

                          \caption@style . . . . 40
                          \captionlabel . . . . . 38
                          \captiontext . . . . . . 39

\chapter . . . . . . . . . 116

                          \contcaption . . . . . 2, \underline{8}
                          \contsubbottom . . . .

. . . . . . 7, \underline{159}, 197

                          \contsubfigure . . 7, \underline{196}
                          \contsubtable . . . 7, \underline{196}
                          \contsubtop . 7, \underline{176}, 196

\csname . . 16, 56, 63, 89, 90, 133, 134, 153

D \do . . . . . . . . . . . . . 188

E \edef . . . . . . . . . . . . 89

                          \endcsname 16, 56, 63,

89, 90, 133, 134, 153 \ext@type . . . . . . . . . 8

F

                          \figurename . . . . . . . 68
                          \fleg@figure . . . . . . \underline{67}
                          \fleg@table . . . . . . . \underline{67}
                          \flegtoc@figure . . . \underline{65}
                          \flegtoc@table . . . . \underline{65}
                          \flegtoc@type . . . . . . 5
                          \fnum@type . . . . . . . . 8
                          \formatlegend . . . . .

. . . . . 3, 30, \underline{32}, 63

H \hb@xt@ . . . . . . . . . . 49

I

                          \if@contbotsub 125, \underline{143}
                          \if@contsubfigxx . .

. . . . . . \underline{4}, 121, 145

                          \if@minipage . 12, 26, 59
                          \if@restonecol . . . . 118
                          \if@twocolumn . . . . . 111

\ifcat . . . . . . . . . . . 82

                          \ignorespaces . . . . .

. . 16, 30, 131, 134

L \label . . . . . . . . . . . 124 \legend . . . . . . . . . 2, \underline{22}

                                                   \linewidth . . . . . . . 37
                                                   \listfloats . . . . . 6, \underline{106}

M

                                                   \MakeUppercase 110, 116

N

                                                   \namedlegend . . . . . 4, \underline{53}
                                                   \newfixedcaption . 5, \underline{69}
                                                   \newflo@tctr . . . . . . \underline{75}
                                                   \newfloatenv . . . . . 6, \underline{79}

\newif . . . . . . . . . 4, 143 \noexpand . . . . . 90, 131

                                                   \normalsize . . 15, 29, 62

O

                                                   \onecolumn . . . . . . . 112

\opt@rg . . . . . . . . 81, 82

P

                                                   \PackageError . 103, 107
                                                   \PackageWarning . . . 85
                                                   \providecommand . . . 74
                                                   \providefixedcaption

. . . . . . . . . . 5, \underline{69}

                                                   \ProvidesPackage . . . 3

R

                                                   \realcaptionwidth . 37
                                                   \renewfixedcaption 5, \underline{69}

S \sbox . . . . . . . . . . . . 44 \section . . . . . . . . . 110 \string . . . . . . 126, 130

                                                   \subbottom . 7, 139, \underline{150}
                                                   \subconcluded . . . 7, \underline{146}
                                                   \subfig@oldcontcaption

. . . . . . . . 185, 187

                                                   \subfigure . . . . . . . \underline{139}

\subtable . . . . . . . . \underline{139} \subtop …. 7, 140, \underline{168}

T

                                                   \tablename . . . . . . . 67
                                                   \twocolumn . . . . . . . 118

U

                                                   \usecaptionstyle . . 40

V \value . . 92, 93, 147, 148

X \xdef . . . . . . . . . . . . 127