Debian Codegraph @

texmf-dist/doc/latex/captdef/captdef.tex

raw
1 \documentclass[a4paper]{article}
2 \usepackage[a4paper]{geometry}
3 \usepackage{miscdoc}
4 \usepackage[scaled=0.85]{luximono}
5 \begin{document}
6 \title{The \Package{captdef} package}
7 \author{Robin Fairbairns\thanks{Email: \emph{[email protected]}}}
8 \maketitle
9
10 \section{Why this package?}
11
12 \LaTeX{} provides a command (\cs{caption}) for adding a caption to a
13 float environment (that is to say, a \texttt{figure} or a
14 \texttt{table}, ``out of the box'').
15
16 The command is a good one, and many users want to use it. Often,
17 they end up using a float environment, in a case where it's not
18 strictly necessary, and get entangled in the positioning problems
19 that floats pose for the innocent user. Using this package, the
20 user can have standard-looking captions without the need of a float
21 environment.
22
23 This package defines a means of defining caption commands, which
24 creates things that look as if they were created by \cs{caption}, and
25 which work outside of a float.
26
27 The \textsf{float} package provides an alternative to
28 \cs{captdef}-defined commands, in the float \texttt{[H]} option
29 (``place the environment \emph{here} without doing any of this
30 floating stuff''). So why use \Package{captdef}?\,---\,its great
31 advantage is simplicity; you load it, and it defines just \emph{three}
32 macros, while \textsf{float} defines lots and lots. (Of course, if
33 you need others of \textsf{float}'s capabilities, \textsf{captdef}
34 loses its advantage\dots).
35
36 \section{How the package works}
37
38 The package defines a command
39 \begin{quote}
40 \cmdinvoke*{DeclareCaption}{command}{counter}
41 \end{quote}
42 which creates a `caption'-like command, which uses \texttt{counter}
43 for its numbering.
44
45 The package then goes on to declare the commonly-needed caption
46 commands \cs{figcaption} and \cs{tabcaption}:
47 \begin{quote}
48 \cmdinvoke{captdef}{\cs{figcaption}}{figure}\\
49 \cmdinvoke{captdef}{\cs{tabcaption}}{table}
50 \end{quote}
51
52 \section{The potential problem}
53
54 Commands defined by \cs{captdef} place a caption in text, and also step the
55 \environment{figure} (or \environment{table} or whatever) counter. The float
56 environments do the same.
57
58 Now, consider the sequence:
59 \begin{quote}
60 \begin{verbatim}
61 <earlier text>
62 \begin{figure}
63 <figure stuff>
64 \caption{...}
65 \end{figure}
66 ...
67 <intervening text>
68 ...
69 <inline figure stuff>
70 \figcaption{...}
71 \end{verbatim}
72 \end{quote}
73 and suppose the \environment{figure} environment doesn't fit anywhere
74 between where it's specified and the inline figure (so that it will
75 float to somewhere later).
76
77 We will then see a document with
78 \begin{quote}
79 \meta{earlier text}\\
80 \dots\\
81 \meta{intervening text}\\
82 \dots\\
83 \meta{inline figure stuff}\\
84 Figure \meta{n+1}: \dots\\
85 \dots\\
86 \meta{yet more text}\\
87 \dots\\
88 \meta{figure stuff}\\
89 Figure \meta{n}: \dots
90 \end{quote}
91 That is, the figure numbers have got out of order, because the
92 floating figure was specified before the inline figure.
93
94 \LaTeX{} won't do this when everything is specified as a float: it
95 keeps floats of the same type in order (which is why floats stack up
96 if a single one won't fit).
97
98 The moral of that little tale is to say: don't use
99 \cs{captdef}-defined commands with floats of the same type in the same
100 document. (Or be extra-specially careful about what's happening if
101 you must.)
102 \end{document}