Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted
\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}
share|improve this answer
1  
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 7 '11 at 8:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.