40

I recently discovered the very nice cleveref package, and really like it. Works much better than autoref (from hyperref) for me. There is only one thing I don't like: If, for example, the \cref command inserts the text "Lemma 1", then only "1" is a clickable hyperlink. When using \autoref, the whole text is a hyperlink, which I really prefer (it's easier to hit the link this way).

Is there any way to get cleveref to work like this, too? Preferably one where I do not need to manually redefine the formatting for every reference type individually (i.e. for lemma, theorem, proposition, section, subsection, ...).

1

1 Answer 1

51

Pass the nameinlink option to the cleveref package

\usepackage[nameinlink]{cleveref}

A MWE follows, just for demonstration- see Section 6.2 of the documentation for details

\documentclass{article}
\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}

\begin{document}

\section{Here is a section}\label{sec:mysection}
\begin{equation}
    f(x)=x^2+\sin(x)
\end{equation}

\cref{sec:mysection}
\end{document}
9
  • 2
    Aha! Seems the version of cleveref (version from 22/03/2011 as shipped with TeXLive 2011) is too old -- it doesn't support this option. Which is some relief, as I swear I searched the manual back and forth (I hate to ask questions and then find out they are answered in the manual). Time to upgrade the package, I guess. Thank you very much!
    – Max Horn
    Commented May 3, 2012 at 17:00
  • @Fingolfin not sure I understand- this works fine for me. Perhaps an update is in order? (I'm on TeXlive 2011), and my version of cleveref is dated 2012/03/07
    – cmhughes
    Commented May 3, 2012 at 17:02
  • 1
    @Fingolfilm -- If you still have the 22/03/2011 version of cleveref (instead of the current version, 0.18.5, dated 07/03/2012), your system may not be set up in a way that runs tlmgr (TeX Live Manager) from time to time to obtain the latest versions of various LaTeX packages. The nameinlink option of the cleveref package was added last fall. Do consult your sys admin (maybe you?) and ask him/her to run tlmgr update --self --all. (Superuser privileges are required to run this command.)
    – Mico
    Commented May 3, 2012 at 17:21
  • @Mico great tip :) Note that one can change the permissions of /usr/local/texlive to be a normal user, in which case tlmgr does not need to be run as an admin. I'm not necessarily recommending it, just an FYI
    – cmhughes
    Commented May 3, 2012 at 17:25
  • 1
    @Fingolfin -- I can understand your reluctance to run tlmgr entirely automatically. However, by not running tlmgr on a regular basis, you do incur the extra burden of having to be diligent about keeping an eye out for what's going on in the TeX world in terms of packages and updates -- including occasional significant improvements, as recently was the case with the cleveref package. Note that you can run tlmgr update --list --all to find out which packages would be updated (but without actually doing anything), and tlmgr update <pkg> to selectively update only one package at a time.
    – Mico
    Commented May 3, 2012 at 18:01

You must log in to answer this question.

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