Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LaTeX figure \caption question

789 views
Skip to first unread message

Brian J. Reiser

unread,
Aug 30, 1990, 3:55:25 PM8/30/90
to
Is there any simple way to modify the formatting of latex figure
captions? I have some longish captions (approx 3-4 sentences) that
are associated with some graphs included in the document as figures.
The default formatting for \caption is apparently the normal text
size, and if the text is longer than one line, it is in a paragraph
the same width as the text. I would like to have the captions printed
slightly smaller, and in a width indented from the width of the text.

At the suggestion of a colleague, I tried defining my own version of \caption:

\newcommand{\figcaption}[1]{\begin{center}
\parbox[t]{5in}{\caption{\protect\small #1}}
\end{center}}

But this is not ideal because (1) only the text of the caption is made
the smaller size, but the words "Figure 11" are the regular text size,
and (2) extra vertical space is skipped above the parbox, so that the
caption is further from the picture in the figure than it would
otherwise be.

Does anyone have a better suggestion? Are there some size and
indentation parameters I could simply adjust that are used by
\caption, or is there a better way to define my own caption?

Thanks,
Brian J. Reiser
Princeton University
Cognitive Science Laboratory
Internet: rei...@princeton.edu

Hosek, Donald A.

unread,
Aug 30, 1990, 10:16:57 PM8/30/90
to
In article <78...@helios.TAMU.EDU>, jdm...@diamond.tamu.edu (James Darrell McCauley) writes...
->In article <BJR.90Au...@clarity.Princeton.EDU>,
->b...@clarity.Princeton.EDU (Brian J. Reiser) writes:
->|> Is there any simple way to modify the formatting of latex figure
->|> captions? I have some longish captions (approx 3-4 sentences) that
->|> are associated with some graphs included in the document as figures.
->|> The default formatting for \caption is apparently the normal text
->|> size, and if the text is longer than one line, it is in a paragraph
->|> the same width as the text. I would like to have the captions printed
->|> slightly smaller, and in a width indented from the width of the text.

->|> At the suggestion of a colleague, I tried defining my own version of
->\caption:

->|> \newcommand{\figcaption}[1]{\begin{center}
->|> \parbox[t]{5in}{\caption{\protect\small #1}}
->|> \end{center}}
->....
->|> Does anyone have a better suggestion?

->Is this better? The words "Figure 11" are the same size as the text:

->\newcommand{\figcaption}[1]{\begin{center}
-> \addtocounter{figure}{1}
-> \parbox[t]{5in}{\protect\small
-> Figure \thefigure : #1}
-> \end{center}}

Sigh.

Suppose he wanted a list of figures too?

OK, the correct way for changing the formatting of a caption:
LaTeX defines \caption so that the actual printing of the caption
text is handled by the \@makecaption macro. For example,
article.sty defines \@makecaption to center the caption if it is
one line or less and to typeset it as a paragraph otherwise with
the definition:

% \@makecaption{NUMBER}{TEXT} : Macro to make a figure or table caption.
% NUMBER : Figure or table number--e.g., 'Figure 3.2'
% TEXT : The caption text.
% Macro should be called inside a \parbox of right width, with \normalsize.
% changed 25 Jun 86 to fix according to Howard Trickey:
% instead of \unhbox\@tempboxa\par we do #1: #2\par

\long\def\@makecaption#1#2{
\vskip 10pt
\setbox\@tempboxa\hbox{#1: #2}
\ifdim \wd\@tempboxa >\hsize % IF longer than one line:
#1: #2\par % THEN set as ordinary paragraph.
\else % ELSE center.
\hbox to\hsize{\hfil\box\@tempboxa\hfil}
\fi}

The following code (placed in mycaption.sty, say) will produce
centered nine-point captions in 10pt text (the caption size will
increase with the text size as \small grows).

\long\def\@makecaption#1#2{
\begin{center}
\small
#1: #2\par
\end{center}}

Note that the \vskip was removed since the center environment
carries its own space around with it.

-dh

---
Don Hosek TeX, LaTeX, and Metafont support, consulting
dho...@ymir.claremont.edu installation and production work.
dho...@ymir.bitnet Free Estimates.
uunet!jarthur!ymir Phone: 714-625-0147
finger dho...@ymir.claremont.edu for more info

Karsten Spang

unread,
Aug 31, 1990, 3:05:42 AM8/31/90
to
In article <BJR.90Au...@clarity.Princeton.EDU>, b...@clarity.Princeton.EDU (Brian J. Reiser) writes:
> Is there any simple way to modify the formatting of latex figure
> captions?
>...

> I would like to have the captions printed
> slightly smaller, and in a width indented from the width of the text.

This is how I use to do it, it is a simple minded approach that does not
change any existing definitions, you have to do some extra typing, but on
the other hand, using an editor, you just copy your last figure.

After \begin{document} I insert the lines

\newlength{\capwidth}
\setlength{\capwidth}{\textwidth}
\addtolength{\capwidth}{-2cm}

and each figure I make like

\begin{figure}[htbp]
\begin{center}
\begin{picture}(x,y)
\put(a,b){...}
...
\end{picture}
\parbox{\capwidth}{
\caption[Short caption for LOF]
{This is the long caption that I need to break over
several lines, because it does not fit on one line.
Consequently, it would exceed TeX capacity, and it
would look awful, if included in the list of tables}
\label{fig:something}
}
\end{center}
\end{figure}

This scheme indents the caption 1cm from the left and right, but it does
not change the point size of the caption.

Karsten
--------------------------------------------------------------------------------
InterNet: sp...@nbivax.nbi.dk (nbivax=129.142.100.3) Karsten Spang
NORDUNET/HEPnet:NBIVAX::SPANG (NBIVAX=21.601=22105) Niels Bohr Institutet
VAXPSI MAIL: (0)238301032352::SPANG Blegdamsvej 17
Phone: +45 31 42 16 16 ext. 255 Fax: +45 31 42 10 16 DK-2100 Copenhagen X
Direct: +45 31 42 42 84-255 Telex: 15216 nbi dk Denmark

James Darrell McCauley

unread,
Aug 30, 1990, 9:52:36 PM8/30/90
to
In article <BJR.90Au...@clarity.Princeton.EDU>,
b...@clarity.Princeton.EDU (Brian J. Reiser) writes:
|> Is there any simple way to modify the formatting of latex figure
|> captions? I have some longish captions (approx 3-4 sentences) that
|> are associated with some graphs included in the document as figures.
|> The default formatting for \caption is apparently the normal text
|> size, and if the text is longer than one line, it is in a paragraph
|> the same width as the text. I would like to have the captions printed
|> slightly smaller, and in a width indented from the width of the text.
|>
|> At the suggestion of a colleague, I tried defining my own version of
\caption:
|>
|> \newcommand{\figcaption}[1]{\begin{center}
|> \parbox[t]{5in}{\caption{\protect\small #1}}
|> \end{center}}
...

|> Does anyone have a better suggestion?

Is this better? The words "Figure 11" are the same size as the text:

\newcommand{\figcaption}[1]{\begin{center}
\addtocounter{figure}{1}


\parbox[t]{5in}{\protect\small

Figure \thefigure : #1}
\end{center}}

--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James Darrell McCauley jdm...@diamond.tamu.edu
Dept of Ag. Engineering (409) 845-6484
Texas A&M University, College Station, Texas 77843-2117, USA
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Hosek, Donald A.

unread,
Aug 31, 1990, 10:00:33 AM8/31/90
to
In article <482.26...@nbivax.nbi.dk>, sp...@nbivax.nbi.dk (Karsten Spang) writes...

>In article <BJR.90Au...@clarity.Princeton.EDU>, b...@clarity.Princeton.EDU (Brian J. Reiser) writes:
>> Is there any simple way to modify the formatting of latex figure
>> captions?
>>...

>> I would like to have the captions printed
>> slightly smaller, and in a width indented from the width of the text.

>This is how I use to do it, it is a simple minded approach that does not


>change any existing definitions, you have to do some extra typing, but on
>the other hand, using an editor, you just copy your last figure.

What about when you take this document and submit it
electronically? Have you considered what it's like for the poor
editor (of the human variety) who has to go through your document
looking for every place where you did this and put it back to a
normal \caption so that the formatting matches the house style?
(Speaking as someone who has been in this position, it's no
trvial matter to make these changes, even with a good text
editor.)

David J. Sturman

unread,
Sep 1, 1990, 10:40:35 AM9/1/90
to
In article <BJR.90Au...@clarity.Princeton.EDU> b...@clarity.Princeton.EDU (Brian J. Reiser) writes:
>Is there any simple way to modify the formatting of latex figure
>captions? I have some longish captions (approx 3-4 sentences) that

I had the same problem and solved it by defining my own caption macro for
LaTeX, shown below. It provides a multi-line caption centered and .25
inches shorter than the currently operating paragraph width, in a slightly
smaller font. The macros take two arguments, the caption title that gets
put into a table of contents, and the paragraph of text that should follow.
Note that the first argument, the 'caption title', is not printed with the
figure so that you have to repeat the title in the second argument.
The macro is:

\newcommand{\mycaption}[2]{
\begin{center}
\advance\textwidth by -0.5in
\parbox{\the\textwidth}{
\caption[#1]{\small #2 \normalsize}
} % end of parbox
\end{center}
} % end of newcommand

You use it in the following way. The caption is "My caption title" and I
have it printing out in italics (\em).

\begin{figure}
\label{a-nice-figure}
\psfig{figure=a-nice-figure.ps}
\mycaption
{My caption title} {{\em My caption title}\ \ This is a long paragraph that
is to be put as comment to the caption of a figure in a document. It can
go on and on...
...
...
and ends here }
\end{figure}

Good luck.

David Sturman
MIT Media Lab
d...@media-lab.media.mit.edu

Brian J. Reiser

unread,
Sep 3, 1990, 12:09:17 PM9/3/90
to
In article <82...@jarthur.Claremont.EDU> dho...@sif.claremont.edu (Hosek, Donald A.) writes:

In article <78...@helios.TAMU.EDU>, jdm...@diamond.tamu.edu (James Darrell McCauley) writes...
->In article <BJR.90Au...@clarity.Princeton.EDU>,
->b...@clarity.Princeton.EDU (Brian J. Reiser) writes:
->|> Is there any simple way to modify the formatting of latex figure
->|> captions? I have some longish captions (approx 3-4 sentences) that
->|> are associated with some graphs included in the document as figures.
->|> The default formatting for \caption is apparently the normal text
->|> size, and if the text is longer than one line, it is in a paragraph
->|> the same width as the text. I would like to have the captions printed
->|> slightly smaller, and in a width indented from the width of the text.

OK, the correct way for changing the formatting of a caption:


LaTeX defines \caption so that the actual printing of the caption
text is handled by the \@makecaption macro. For example,
article.sty defines \@makecaption to center the caption if it is
one line or less and to typeset it as a paragraph otherwise with
the definition:

[original \@makecaption macro and hosek's revision deleted]

Thanks to everybody for their suggestions on how to solve this
problem. The solution I pulled together from everybody's suggestions is:

\long\def\@makecaption#1#2{
\vskip 10pt

\setbox\@tempboxa\hbox{\small #1: #2}
\ifdim \wd\@tempboxa >0.8\hsize % IF longer than one line:
\quote {\small #1: #2\par}\endquote % THEN set as quote paragraph


\else % ELSE center.
\hbox to\hsize{\hfil\box\@tempboxa\hfil}
\fi}

-- Brian Reiser
Cognitive Science Laboratory
Princeton University

0 new messages