59

Possible Duplicate:
Table, Figure, and Listing prefixes
Automatically inserting “Section, Subsection, etc”

I'm using the package hyperref. When referencing my figure, I currently use code like

Figure \ref{fig:chorus-overview} gives an overview of the basic concept.

because \ref will just yield a single integer 1, as opposed to Figure 1.

However, the word Figure is auto-generated for the figure environment caption, so when using a package such as [ngerman]{babel}, it's Abbildung instead, and I need to fix the text before my reference.

Is there any way to directly get the Figure 1 text via \ref or a similar command?

EDIT

Additionally to the steps described in Sveinung's answer (using \autoref from hyperref or \cref from cleveref), I needed to make sure to place the label before the caption in the figure environment, as pointed out by Werner, and to include babel before hyperref/cleveref.

\nameref does not do what I need, since it copies the text of the caption instead.

mic_e
  • 755
  • Since the question most likely has something to do with the placement of labels, and/or babel options, it is probably not an exact duplicate. – Sveinung Jul 08 '12 at 14:32
  • +1 for mentioning that the label needs to go before the caption. – Will May 02 '14 at 17:07

1 Answers1

66

Load the package cleveref and change your \ref{label} to \cref{label}. If you prefer to include the label names (chapter, section etc.) in the hyperlinks when using cleveref, you can pass the nameinlink option to the cleveref package, see page 10 in the cleveref-manual.

As egreg emphasizes, the package cleveref must be loaded after hyperref.

You may instead use \autoref from the hyperref-package, just change your \ref{label} to \autoref{label}. See the hyperref manual page 15.

If I misunderstood you, and the problem is that you want the English word Figure instead of the German word Abbildung, you have two possibilities:

  1. Either load babel with the option UKenglish instead of ngerman if your text is in English, or
  2. if your text is in German, but you still want to use the English word figure, you can use the babel-environment \begin{otherlanguage} before your figure, see the babel-manual page 6 (use texdoc babel at a command prompt).
Sveinung
  • 20,355