14
\documentclass{scrbook}

\usepackage{listings}
\usepackage{cleveref}

\begin{document}

Ref: \ref{test}.
Cref: \cref{test}.

\begin{lstlisting}[caption={Test},label={test}]
test
\end{lstlisting}

\end{document}

This produces Ref: 1. Cref: ?? 1.. I expected something like Ref: 1. Cref: Listing 1.

I get a LaTeX Warning: \Cref reference format for label type 'lstlisting' undefined on input line 9.

8
  • 2
    Works for me. What versions are you using? Mar 10, 2012 at 5:44
  • ("C:\Program Files\MiKTeX 2.9\tex\latex\cleveref\cleveref.sty" Package: cleveref 2011/03/22 v0.17.9 Intelligent cross-referencing Package cleveref Info: listings' support loaded on input line 2312.)` Please check you log file. Mar 10, 2012 at 5:48
  • I am using the last version from here: ctan.org/tex-archive/macros/latex/contrib/cleveref
    – Dennis
    Mar 10, 2012 at 5:54
  • @YiannisLazarides - I added the same log meesage to my question.
    – Dennis
    Mar 10, 2012 at 5:55
  • 1
    Can you pleae read you .log file and post the version number? Mar 10, 2012 at 5:56

1 Answer 1

25

Solution 1

Add the following to your header:

\crefname{lstlisting}{listing}{listings}
\Crefname{lstlisting}{Listing}{Listings}

Solution 2

Download the newest version from here (cleveref.dtx and cleveref.ins) and run latex cleveref.ins.

7
  • As I mentioned in the comments, your original MWE works fine if you just run it twice. Mar 12, 2012 at 4:09
  • It didn't, even after running it 10 times, because of the LaTeX Warning: \Cref reference format for label type 'lstlisting' undefined on input line 9.. Seriously, my cleveref version was to old :).
    – Dennis
    Mar 12, 2012 at 4:27
  • The link shows version 0.19 2013-12-28. tlmgr info cleveref tells I run 0.19 2014-02-26 which I assume is even newer. Still, I ran latex several times, and it would not detect the listing as a listing. Had to go with solution 1 :(
    – mcnesium
    Nov 26, 2015 at 10:20
  • 2
    @Dennis Just a small hint: The call to \Crefname is superfluous in the above case. As mentioned in section 8.1.2 of the cleveref documentation, "If the corresponding \Crefname is undefined when \crefname is called, it will automatically define \Crefname to be a capitalised version of \crefname, using \MakeUppercase."
    – Janosh
    Aug 11, 2016 at 22:03
  • 5
    For those who run into the same issue having installed the current version as @mcnesium: Make sure that listings is included BEFORE cleveref!
    – tbolender
    May 28, 2017 at 16:06

You must log in to answer this question.

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