32

I'm using the \autoref tag which comes with the package hyperref for referencing my algorithms, figures etc. I read that it automatically adjusts the reference text's case, but it won't work with my setup. When I compile the code, everything (page, text, link) is correctly put, except the case like in the following example:

As it can be seen in Figure 9.7, this [...]

Remark: there may be something wrong with my setup - links to text sections (like chapter, section, subsection) and also floating environments like "algorithm" (algorithm2e.sty) do have the correct case. The case is wrong when refering to Figures and Equations.

1
  • 5
    Note that it is quite conventional usage to use capital when referring to figures, so it isn't really "wrong" just different. It also avoids the problem of sentence starting. May 17, 2012 at 16:37

2 Answers 2

35

hyperref.sty indeed includes the following code snippet (with names sometimes, but not always in uppercase):

\def\HyLang@english{%
  \def\equationautorefname{Equation}%
  \def\footnoteautorefname{footnote}%
  \def\itemautorefname{item}%
  \def\figureautorefname{Figure}%
  \def\tableautorefname{Table}%
  \def\partautorefname{Part}%
  \def\appendixautorefname{Appendix}%
  \def\chapterautorefname{chapter}%
  \def\sectionautorefname{section}%
  \def\subsectionautorefname{subsection}%
  \def\subsubsectionautorefname{subsubsection}%
  \def\paragraphautorefname{paragraph}%
  \def\subparagraphautorefname{subparagraph}%
  \def\FancyVerbLineautorefname{line}%
  \def\theoremautorefname{Theorem}%
  \def\pageautorefname{page}%
}

Solution: Redefine the "offending" name macros.

\documentclass{article}

\usepackage{hyperref}

\renewcommand*{\figureautorefname}{figure}

\begin{document}

\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{foo}\label{fig:foo}
\end{figure}

As shown in \autoref{fig:foo}~\dots

\end{document}

enter image description here

5
  • 2
    Thank you @lockstep, that did the trick for the lowercase-case. BUT when a reference is at the start of a sentence, it's not set uppercase. As far as I know autoref should realize this and set the corresponding case, right?
    – Eric
    Nov 30, 2011 at 12:57
  • 3
    @Eric: I'm afraid no. LaTeX can't detect sentence starts automatically; to switch to uppercase manually, you should have a look at the cleveref package and its \cref and \Cref commands.
    – lockstep
    Dec 1, 2011 at 0:39
  • 1
    Why the last code does not work when the package 'babel' is load... Thanks in advance
    – Gitano
    Jan 22, 2013 at 14:52
  • @Gitano See tex.stackexchange.com/questions/82993/…
    – lockstep
    Jan 22, 2013 at 15:46
  • 1
    Thanks, very useful information! With the babel package, for me what worked was to use \addto\extrasenglish{\def\chapterautorefname{Chapter}} (adding the definitions to \captionsenglish didn't work for some reason)
    – phfaist
    Jan 31, 2016 at 16:13
22

As indicated by lockstep you can use cleveref to have control over case. Simply load cleveref, but make sure to load it after hyperref, and use \cref for lower case cross-references and \Cref for upper case cross-references. Other than being able to handle cases cleveref can handle ranges of labels and more languages than \autoref.

Here is an example on how to use it:

\documentclass{article}

\usepackage{mwe}
\usepackage{hyperref}
\usepackage{cleveref}% Has to be loaded after hyperref

\begin{document}

\begin{figure}
  \centering
  \includegraphics[width=.48\linewidth]{example-image-a}
  \caption{foo}\label{fig:foo}
\end{figure}

As shown in \cref{fig:foo}~\dots

\Cref{fig:foo} shows~\dots

\end{document}

Output of example

Note that if you want cross-reference links to include the name, e.g. "fig. 1" and not only "1", you have to load cleveref with the option nameinlink. Also note that if you want it to not abbreviate cross-reference names, e.g. "figure 1" and not "fig. 1", you have to load cleveref with the option noabbrev.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.