代碼列表

代碼列表

我試圖在“列表列表”的條目後面添加一個連字符,如下所示:

代碼列表

代碼1--第一個代碼................................................................ .. 7

代碼2--第二個代碼.............................................. .. 8

使用以下程式碼...

\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}

我有:

代碼列表

代碼1 第一個代碼............................................ .... 7

代碼2 第二個代碼................................................ .... 8

預先感謝您的任何幫助。

答案1

這是使用的一種可能性tocloft包和一部分艾格格的回答自訂 \lstlistoflistings 產生的清單清單?

\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}

在此輸入影像描述

相關內容