![如何在附录中创建单独的列表索引?](https://linux22.com/image/372442/%E5%A6%82%E4%BD%95%E5%9C%A8%E9%99%84%E5%BD%95%E4%B8%AD%E5%88%9B%E5%BB%BA%E5%8D%95%E7%8B%AC%E7%9A%84%E5%88%97%E8%A1%A8%E7%B4%A2%E5%BC%95%EF%BC%9F.png)
我想在我的文档中包含一个单独的代码清单索引。因此,清单应该重新从 0 开始计数。但是当我重置计数器时,清单(当然)再次出现在文档第一部分的清单表中。但我希望它们列在附录中的新索引中。(我希望这不会太难理解。。抱歉解释得不好)。
我不希望列表被计入整个文档的开头,但我希望在附录中有一个新的索引。
\documentclass[a4paper,12pt,parskip,bibtotoc,liststotoc]{article}
\usepackage{listings}
\begin{document}
\addcontentsline{toc}{section}{Listingverzeichnis}
\lstlistoflistings
\begin{lstlisting}[language=Ruby,caption={listing 1}]
this is the first listing
\end{lstlisting}
\begin{appendix}
\begin{lstlisting}[language=Ruby,caption={listing 2}]
this is the second listing
\end{lstlisting}
\end{appendix}
\end{document}
第二个列表的示例是我想要在附录中的单独列表表中编入索引的内容。
我很高兴收到任何建议感谢您的帮助!
答案1
这将应用一个本地补丁\lstlistoflistings
以便使用.apl
(含义appendix listings
)并保存文件句柄\tf@lol
并将附录列表存储到另一个文件中。
以防万一hyperref
应该使用:我lstlisting
在附录中为计数器提供了一个新的超级锚点。
\documentclass[a4paper,12pt]{article}
\usepackage{listings}
\usepackage{xpatch}
%\usepackage{hyperref}% Just in case....
\providecommand{\phantomsection}{}
\makeatletter
\newcommand{\appendixlistingname}{Appendix Listings}
\newcommand{\listofappendixlistings}{%
% Applying the same trick as listings does with \lstlistoflistings: Modifying \@starttoc such that it can load only .apl files
\begingroup
\let\@starttoc@orig\@starttoc%
\renewcommand{\contentsname}{\appendixlistingname}
\renewcommand{\@starttoc}[1]{%
\@starttoc@orig{apl}%
}%
\phantomsection
\addcontentsline{toc}{section}{\appendixlistingname}
\tableofcontents% Calling \tableofcontents with the `.apl` file instead of `.toc`
\endgroup
}
\xapptocmd{\appendix}{%
\setcounter{lstlisting}{0}%
\@ifundefined{theHlstlisting}{%
}{%
\renewcommand{\theHlstlisting}{appendix}
}%
\write\@auxout{%
\string\let\string\latex@tf@lol\string\tf@lol% Store the original `\tf@lol` file handle
\string\let\string\tf@lol\string\tf@apl%
}%
}{}{}
\makeatother
\begin{document}
\addcontentsline{toc}{section}{Listingverzeichnis}
\lstlistoflistings
\begin{lstlisting}[language=Ruby,caption={listing 1}]
this is the first listing
\end{lstlisting}
\begin{lstlisting}[language=Ruby,caption={listing 2}]
this is another listing in the main part
\end{lstlisting}
\clearpage
\appendix
\listofappendixlistings
\clearpage
\begin{lstlisting}[language=Ruby,caption={listing 3}]
This is the third listing
\end{lstlisting}
\begin{lstlisting}[language=Ruby,caption={listing 4}]
This is the fourth listing
\end{lstlisting}
\end{document}