[texhax] referencing figures, prepend word "Fig"

Toby Cubitt tsc25 at cantab.net
Wed Apr 9 10:27:27 CEST 2008

Philip TAYLOR wrote:
 > Better, perhaps,
 > \makeatletter
 > \def\p at figure{Fig.~}
 > \def\p at table{Table~}
 > \makeatother

Better still(?), use one of the many existing packages that let you do 
this. The fancyref package does exactly what you asked for: adds a 
string before cross-references (e.g. "Figure") that depends on the label 
prefix, i.e. the part before the colon in \label{fig:foobar}. All you 
have to do is define the strings and prefixes.

Or you could use the cleveref package, which adds the correct string 
irrespective of the label. E.g. if you changed a figure into a table, 
but forgot to rename \label{fig:foobar}, it would add "Table" instead of 
"Figure", even though the label uses the wrong prefix. It can do this 
because, as Donald Arseneau wrote, LaTeX already knows if it's a figure 
or table, or (with a bit of work) equation or theorem or list item etc. 
(Disclosure of interest: I'm the author of cleveref.)



> Donald Arseneau wrote:
>> You got an answer to this question, but did you know that
>> LaTeX already knows if it is a figure or table, regardless 
>> of the tag?   Just use that:
>> \makeatletter
>> \def\p at figure{Fig~}
>> \def\p at table{Table~}
>> \makeatother

More information about the texhax mailing list