[comp.text.tex] LaTex \caption command

bruggink@vms.macc.wisc.edu (03/05/91)

The \caption command generates *both* table and figure captions;  I want
table captions to be in a different font and format than figure captions,
and I want to continue using "\caption" so that the auto-numbering of
tables and figures is preserved.

Can anyone suggest a way to do this within a .STY file??

--dennis bruggink
  bruggink@vms.macc.wisc.edu     bruggink@ccc.nersc.gov

ogawa@orion.arc.nasa.gov (Arthur Ogawa) (03/05/91)

In article <1991Mar4.224724.2116@macc.wisc.edu> bruggink@vms.macc.wisc.edu writes:
|
|The \caption command generates *both* table and figure captions;  I want
|table captions to be in a different font and format than figure captions,
|and I want to continue using "\caption" so that the auto-numbering of
|tables and figures is preserved.
|
|Can anyone suggest a way to do this within a .STY file??

The bad news is that I couldn't figure a way to do this purely within a STY 
file. The good news is that only a slight modification (backward compatible)
to LaTeX is needed to accomplish our goal.

A comment: The poster correctly chooses to continue to use the same markup 
for the caption no matter whether it lies within a figure or table.
This is a choice in favor of descriptive markup---the correct choice IMHO.

************* cut here---beginning of Bruggink.sty **********
% Bruggink.sty---provide for independent formatting for float captions.
% The following is a re-definition of the \@caption macro which lets
% you format your figure captions differently from your table captions, etc.
% Your .sty file must provide for a meaning for, e.g., \@makefigurecaption, 
% etc.  If you do not, the default \@makecaption will be used.
\long\def\@caption#1[#2]#3{\par\addcontentsline{\csname
  ext@#1\endcsname}{#1}{\protect\numberline{\csname
  the#1\endcsname}{\ignorespaces #2}}\begingroup
    \@parboxrestore
    \normalsize
    \expandafter\let\expandafter\@tempa\csname @make#1caption\endcsname
    \ifx\@tempa\relax\let\@tempa\@makecaption\fi
    \@tempa{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup}
%
% Here is the content of a .sty file containing definitions using the above
hook.
%
% The following is the same as the \@makecaption in book.sty:
\long\def\@makefigurecaption#1#2{%
 \vskip 10pt 
 \setbox\@tempboxa\hbox{#1: #2}%
 \ifdim \wd\@tempboxa >\hsize #1: #2\par \else \hbox
to\hsize{\hfil\box\@tempboxa\hfil}% 
 \fi}
%
% The following is slightly different from the \@makecaption in book.sty:
\long\def\@maketablecaption#1#2{%
 \vskip 10pt 
 \setbox\@tempboxa\hbox{#1. #2}%
 \ifdim \wd\@tempboxa >\hsize #1. #2\par \else \hbox
to\hsize{\hfil\box\@tempboxa\hfil} %
 \fi}
************* cut here---end of Bruggink.sty **********

And here is a document instance to test the above .sty. Note that this .sty
is tested here with book.sty; it should work equally well with article.sty

************* cut here---beginning of Bruggink.tex **********
% Bruggink.tex---illustrate how to use Bruggink.sty
\documentstyle{book}
\documentstyle{bruggink}
\begin{document}

\begin{figure}[h]
Content of figure
\caption{Figure caption}%
\end{figure}

\begin{table}[h]
Content of table
\caption{Table caption}%
\end{table}

\end{document}
************* cut here---end of Bruggink.tex **********

Hope this helps,
Art Ogawa
TeX Consultants

graeme@otago.ac.nz (03/06/91)

In article <1991Mar4.224724.2116@macc.wisc.edu>, bruggink@vms.macc.wisc.edu 
writes:
> 
> The \caption command generates *both* table and figure captions;  I want
> table captions to be in a different font and format than figure captions,
> and I want to continue using "\caption" so that the auto-numbering of
> tables and figures is preserved.
> 
> Can anyone suggest a way to do this within a .STY file??
> 
> --dennis bruggink
>   bruggink@vms.macc.wisc.edu     bruggink@ccc.nersc.gov

The command for formatting captions is \@makecaption. 

The \@makecaption command, below, has been redefined to handle tables and
figures differently.

\def\tablecaption{table}
\long\def\@makecaption#1#2{%
   \ifx\@captype\tablecaption     % i.e., a table caption
      \begin{center}
         \footnotesize
         \bf #1 \\                % centre TABLE <no.>
             #2 \par              % centre caption
      \end{center}
   \else                          % a figure caption
      \small
      \vskip 10pt plus4pt minus2pt
      {\it #1:}\quad #2
    \fi}

Such a definition should be placed inside a substyle file.

Place disclaimer here.

Graeme McKinstry              graeme@otago.ac.nz
Computing Services Centre,
University of Otago, Dunedin, New Zealand.

SHEPPEY (n.)                       
Measure of distance (equal to approximately seven eighths of a mile),
defined as the closest distance at which sheep remain picturesque.