[Tex/LaTex] cleveref + listings

cleverefcross-referencinglistings

\documentclass{scrbook}

\usepackage{listings}
\usepackage{cleveref}

\begin{document}

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

\begin{lstlisting}
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.

Best Answer

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.