61

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.

2
  • 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
    Commented Jul 8, 2012 at 14:32
  • +1 for mentioning that the label needs to go before the caption.
    – Will
    Commented May 2, 2014 at 17:07

1 Answer 1

68

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).
6
  • 6
    The package cleveref must be loaded after hyperref. Just a reminder, but it's important because usually it's the other way around and people don't read manuals. :)
    – egreg
    Commented Jul 8, 2012 at 14:11
  • 2
    @mic_e: This may be because you have your \label and \caption command inverted. See Where to put the \label on a figure environment?
    – Werner
    Commented Jul 8, 2012 at 14:20
  • 4
    I've solved the problem now. I made two mistakes: First, I included hyperref before including babel, and second, I placed \label before \caption. Thanks for your help.
    – mic_e
    Commented Jul 8, 2012 at 14:37
  • 1
    @mic_e Note that, with some exceptions such as cleveref, hyperref should be loaded as the last package. See Which packages should be loaded after hyperref instead of before? Commented Jul 8, 2012 at 14:52
  • 1
    just a tiny thing, it generates fig. x.y, while i would prefer Fig. x.y; is there any simple way to achieve that?
    – karlosss
    Commented Jul 28, 2021 at 12:15

Not the answer you're looking for? Browse other questions tagged .