[OS X TeX] Tweaking Figure label

Bruno Voisin bvoisin at mac.com
Wed Feb 7 11:01:51 EST 2007


Le 7 févr. 07 à 16:37, John B. Thoo a écrit :

> A journal wants the figure label in the caption to be in bold, but  
> the reference to the figure in normal text.  I can accomplish the  
> former by editing "article.cls"
>
>   change   \renewcommand \thefigure {\@arabic\c at figure}
>   to       \renewcommand \thefigure {\textbf{\@arabic\c at figure}}
>
>   change   \newcommand\figurename{Figure}
>   to       \newcommand\figurename{\textbf{Figure}}
>
> But then, when I use \ref, the figure number in the text is in bold  
> also.  How do I get out of this dilemma?

Don't edit article.cls. Ever. Instead, copy the corresponding  
extracts from article.cls in the preamble of your LaTeX document,  
between \makeatletter and \makeatother, and perform the redefinition  
there.

In your case that would be:

\makeatletter
\long\def\@makecaption#1#2{%
   \vskip\abovecaptionskip
   \sbox\@tempboxa{\textbf{#1}: #2}%
   \ifdim \wd\@tempboxa >\hsize
     \textbf{#1}: #2\par
   \else
     \global \@minipagefalse
     \hb at xt@\hsize{\hfil\box\@tempboxa\hfil}%
   \fi
   \vskip\belowcaptionskip}
\makeatother

or, in better LaTeX parlance (instead of using plain TeX commands as  
above):

\usepackage{ifthen}
\newsavebox{\tempbox}
\newlength{\templength}
\makeatletter
\renewcommand{\@makecaption}[2]{%
   \vspace{\abovecaptionskip}%
   \sbox{\tempbox}{\textbf{#1}: #2}%
   \settowidth{\templength}{\usebox{\tempbox}}%
   \ifthenelse{\templength>\linewidth}
     {\textbf{#1}: #2\par}
     {\global\@minipagefalse
      \makebox[\linewidth]{\usebox{\tempbox}}}%
   \vspace{\belowcaptionskip}}
\makeatother

However, this is a bit risky in case you don't exactly know what  
you're doing. For example, the hyperref package redefines a *lot* of  
LaTeX internals, and makes the code for these internals very hard to  
decipher. This is not the case here, but often you have to take these  
redefinitions into account when customizing LaTeX to suit your needs.

A much more robust and viable way would be to use a dedicated package  
providing a sensible interface to the customization you're after. The  
LaTeX Companion (2nd edition) is the ultimate reference on those things.

Hope this helps,

Bruno Voisin 
------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/





More information about the MacOSX-TeX mailing list