11

I want to set the caption for referenced listings:

\documentclass{scrbook}

\usepackage{listings}
\usepackage{varioref}
\usepackage{hyperref}
\usepackage{cleveref}
\begin{document}
\crefname{lstlisting}{Quelltext}{Quelltext}
\Crefname{lstlisting}{Quelltext}{Quelltext}

Ref: \ref{test}.
Cref: \vref{test}.
\clearpage
\begin{lstlisting}[caption={Test},label={test}]
test
\end{lstlisting}

\end{document}

According to another post, I'd expect Quelltext 1 but it prints listing 1.

What is wrong?

  • 1
    \crefname{listing}{Quelltext}{Quelltext} works. I don't know why the package decided to use listing instead of lstlisting. – egreg Dec 8 '12 at 21:30
14

Use

\crefname{listing}{Quelltext}{Quelltext}
\Crefname{listing}{Quelltext}{Quelltext}

There is an alias from lstlisting to listing, but apparently it doesn't work.

\documentclass{scrbook}

\usepackage{listings}
\usepackage{varioref}
\usepackage{hyperref}
\usepackage{cleveref}
\begin{document}
\crefname{listing}{Quelltext}{Quelltext}
\Crefname{listing}{Quelltext}{Quelltext}

Ref: \ref{test}.
Cref: \vref{test}.
\clearpage
\begin{lstlisting}[caption={Test},label={test}]
test
\end{lstlisting}

\end{document}

enter image description here

  • 2
    Note: It is important to load package cleveref after loading package listings. – Florian Mar 17 '15 at 12:39
  • @Florian cleveref should always be the last loaded package (with perhaps just a few exceptions). – egreg Mar 17 '15 at 12:41

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.