5

I have to add the word Listing or Lst. in front of the number of a listings in the list-of-listings. I use the listings package. I know how to achieve this with tables:

\renewcommand{\cfttabpresnum}{Tab. }
\settowidth{\cfttabnumwidth}{Tab. 10\quad}

but is there something similar for the listings?

My current code:

\documentclass[12pt,a4paper]{scrartcl}
\usepackage{listings}
\begin{document}
\lstlistoflistings
\section{Test}
\begin{lstlisting}[caption=TestListing]
test()
\end{lstlisting}
\end{document}
Martin Scharrer
  • 262,582

1 Answers1

5
\documentclass[12pt,a4paper]{scrartcl}
\usepackage{listings}
\makeatletter
\def\l@lstlisting#1#2{\@dottedtocline{1}{0em}{1em}{Listing #1}{#2}}
\makeatother
\begin{document}
\lstlistoflistings
\section{Test}

\begin{lstlisting}[caption=TestListing]
test()
\end{lstlisting}
\end{document}
Ulrike Fischer
  • 327,261
  • 2
    You were one minute faster. I was just typing the same answer, but was still wording some explanation text. :-) One suggestion: I would use {\lstlistingname\space#1} instead of {Listing #1} to keep it in sync if the listings name is ever changed, e.g. by babel. – Martin Scharrer Jul 07 '11 at 08:44