Liste der Codes

Liste der Codes

Ich versuche, nach den Einträgen der „List of Listings“ wie folgt einen Bindestrich einzufügen:

Liste der Codes

Code 1--Erster Code ................................ 7

Code 2--Zweiter Code ................................. 8

Mit dem folgenden Code ...

\documentclass[12pt,openright,oneside,dvipsnames,a4paper,%
chapter=TITLE,section=TITLE,english]{abntex2}
\usepackage{textcomp}
\usepackage{caption} 
\usepackage{listings}

\renewcommand{\lstlistingname}{Code}         %  Listings
\renewcommand{\lstlistlistingname}{List of Codes}%

\lstset{
            language = [LaTeX]{TeX}
}

\AtBeginDocument{ %
            \counterwithout{lstlisting}{chapter}
}

\begin{document}

\lstinputlisting[caption={First Code}]{code1.tex}
\lstinputlisting[caption={Second Code}]{code2.tex}

\end{document}

Ich habe:

Liste der Codes

Code 1 Erster Code ................................ 7

Code 2 Zweiter Code ................................. 8

Vielen Dank im Voraus für jede Hilfe.

Antwort1

Hier ist eine Möglichkeit mit demtocloftPaket und Teil vonegregs AntwortZuDie von \lstlistoflistings generierte Liste mit Einträgen anpassen?:

\documentclass[12pt,openright,oneside,dvipsnames,a4paper,%
chapter=TITLE,section=TITLE,english]{abntex2}
\usepackage{textcomp}
\usepackage{caption} 
\usepackage{listings}
\usepackage{tocloft}

\renewcommand\lstlistingname{Code}         %  Listings
\renewcommand\lstlistlistingname{List of Codes}%

\lstset{
  language = [LaTeX]{TeX}
}

\AtBeginDocument{ %
  \counterwithout{lstlisting}{chapter}
}

\newlength\mylen

\begingroup
\makeatletter
\let\newcounter\@gobble\let\setcounter\@gobbletwo
  \globaldefs\@ne \let\c@loldepth\@ne
  \newlistof{listings}{lol}{\lstlistlistingname}
  \newlistentry{lstlisting}{lol}{0}
\makeatother
\endgroup

\renewcommand\cftlstlistingpresnum{\lstlistingname~}
\settowidth\mylen{\cftlstlistingpresnum\cftlstlistingaftersnum}
\addtolength\cftlstlistingnumwidth{\mylen} %
\renewcommand\cftlstlistingaftersnum{\hfill\textendash\hfill}

\begin{document}

\lstlistoflistings

\begin{lstlisting}[caption={First Code}]
code1
\end{lstlisting}

\begin{lstlisting}[caption={Second Code}]
code2
\end{lstlisting}

\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen