27

When I attempt to reference an equation using \cref{..} while also using the package amsmath the references appear as ?? in the outputted pdf. For example

\documentclass[]{article}
\usepackage{graphicx}
\usepackage{cleveref} %for cref
\usepackage{amsmath} %for sub equation numbers and words within equations (\text)

\begin{document}


\section{Introduction}

    \begin{equation}\label{eq:solve}
    x^2 - 5 x + 6 = 0 
    \end{equation}


    Ref: \ref{eq:solve}

    CRef: \cref{eq:solve}

\end{document}

I get the output:

enter image description here

However if the \usepackage{amsmath} is commented out the \cref works correctly.

enter image description here

Is it possible to use both together successfully?

  • 7
    You have to load cleveref last, even after hyperref. – egreg Dec 6 '13 at 15:10
  • @egreg Thank you! That solved the problem. If you post that as an answer I will accept it – Richard Tingle Dec 6 '13 at 15:11
  • you might want to consider using amsmath's \eqref instead of just \ref. \eqref adds parentheses around the reference, and ensures that they (and the reference itself) are always upright. – barbara beeton Dec 6 '13 at 17:17
  • @barbarabeeton Are you refering to my line Ref: \ref{eq:solve}, if so thats just in there to prove that normal references are still working; that only cref that was troublesome – Richard Tingle Dec 6 '13 at 17:18
  • @RichardTingle -- yes, that's what i was referring to, and i understand that it was only for illustration. but some authors find the parenthesized cross reference preferable to the "eq." representation. (it can probably be changed, but not everyone knows about that.) – barbara beeton Dec 6 '13 at 17:58
43

I tried to look for other questions with the same problem and found none. So here's an answer: load cleveref last.

From the documentation:

The cleveref package is loaded in the usual way, by putting the line

\usepackage{cleveref}

in your document’s preamble. However, care must be taken when using cleveref in conjunction with other packages that modify LaTeX’s referencing system (see Section 11). Basically, cleveref must be loaded last.

The problem is that amsmath modifies the referencing system, in order to cope with \tag, for instance. So cleveref has to hook into the redefined macros, rather than the original ones. By loading amsmath after cleveref you don't give the package the chance to know amsmath is also requested.

| improve this answer | |
  • In my case it was below amsmath, but above mathtools and a couple of \newtheorem definitions. Frustrating to have the order matter like that. – Thomas Ahle Mar 13 '19 at 21:03
  • @ThomasAhle As a general rule, I recommend to first load all packages (cleveref last, of course) and then do settings. – egreg Mar 13 '19 at 21:12
  • Makes sense, but then there are other packages, like autonum that also want to be loaded last :( – Thomas Ahle Mar 13 '19 at 22:23

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.