当我尝试时\addtocontents{lst}{\string<code>}
,
没有出现错误,但是代码不起作用。
最小工作示例
请注意,所有列表在附录之前和附录内的条目之间都会清除页面,但 列表列表
除外。lst
[笔记]:还需要创建基本文本文件I.txt
才能运行。
\documentclass[crop=false,float=true,class=scrartcl]{standalone}
\usepackage{listings} % improved version of verbatim. imports script languages (with syntax coloring).
\usepackage[toc,page]{appendix} % appendices. [toc adds Appendices to TOC, page adds a page listed Appendices in the document.]
\usepackage{float} % improves floating objects (graphics/tables).
\usepackage{color} % color commands.
\usepackage[dvipsnames]{xcolor} % additional color commands.
% Settings for importing scripts [listings package]
\lstset{ %
backgroundcolor = \color{white}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
basicstyle = \footnotesize, % the size of the fonts that are used for the code
breakatwhitespace= false, % sets if automatic breaks should only happen at whitespace
breaklines = true, % sets automatic line breaking
captionpos = t, % sets the caption-position
commentstyle = \color{Green}, % comment style
deletekeywords = {...}, % if you want to delete keywords from the given language
escapeinside = {\%*}{*)}, % if you want to add LaTeX within your code
extendedchars = true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
frame = single, % adds a frame around the code
keepspaces = true, % keeps spaces in text,
% useful for keeping indentation of code (possibly needs columns=flexible)
keywordstyle = \color{blue}, % keyword style
language = Matlab, % the language of the code
morekeywords = {*,...}, % if you want to add more keywords to the set
numbers = left, % where to put the line-numbers; possible values are (none, left, right)
numbersep = 5pt, % how far the line-numbers are from the code
numberstyle = \tiny\color{gray}, % the style that is used for the line-numbers
rulecolor = \color{black}, % if not set, the frame-color may be changed on line-breaks within
% not-black text (e.g. comments (green here))
showspaces = false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
showstringspaces = false, % underline spaces within strings only
showtabs = false, % show tabs within strings adding particular underscores
stepnumber = 1, % the step between two line-numbers. If it's 1, each line will be numbered
stringstyle = \color{purple}, % string literal style
tabsize = 2, % sets default tabsize to 2 spaces
title = \lstname % show the filename of files included with \lstinputlisting; also try caption
% instead of title
}
\begin{document}
\pagenumbering{roman}
\tableofcontents \addcontentsline{toc}{section}{List of Contents \vspace{-1em}} \clearpage %\addtocontents {toc}{\string\vspace{-1em}}
\listoffigures \addcontentsline{toc}{section}{List of Figures \vspace{-1em}} \clearpage %\addtocontents {toc}{\string\vspace{-1em}}
\listoftables \addcontentsline{toc}{section}{List of Tables \vspace{-1em}} \clearpage %\addtocontents {toc}{\string\vspace{-1em}}
\lstlistoflistings \addcontentsline{toc}{section}{List of Code Listings } \clearpage
\pagenumbering{arabic}
\setcounter{page}{1}
\section{One}
\begin{figure}[H] \caption{I} \end{figure}
\begin{figure}[H] \caption{II} \end{figure}
\begin{table} [H] \caption{I} \end{table}
\begin{table} [H] \caption{II} \end{table}
\lstinputlisting[caption=I] {I.txt}
\lstinputlisting[caption=II]{I.txt}
\subsection{a}
\subsection{b}
\clearpage
\section{Two}
\begin{figure}[H] \caption{I} \end{figure}
\begin{figure}[H] \caption{II} \end{figure}
\begin{table} [H] \caption{I} \end{table}
\begin{table} [H] \caption{II} \end{table}
\lstinputlisting[caption=I] {I.txt}
\lstinputlisting[caption=II]{I.txt}
\subsection{a}
\subsection{b}
\clearpage
\section{Three}
\begin{figure}[H] \caption{I} \end{figure}
\begin{figure}[H] \caption{II} \end{figure}
\begin{table} [H] \caption{I} \end{table}
\begin{table} [H] \caption{II} \end{table}
\lstinputlisting[caption=I] {I.txt}
\lstinputlisting[caption=II]{I.txt}
\subsection{a}
\subsection{b}
\clearpage
\addtocontents{toc}{\string\clearpage}
\addtocontents{lof}{\string\clearpage}
\addtocontents{lot}{\string\clearpage}
\addtocontents{lst}{\string\clearpage}
\begin{appendices}
\clearpage
\section{A}
\begin{figure}[H] \caption{I} \end{figure}
\begin{figure}[H] \caption{II} \end{figure}
\begin{table} [H] \caption{I} \end{table}
\begin{table} [H] \caption{II} \end{table}
\lstinputlisting[caption=I] {I.txt}
\lstinputlisting[caption=II]{I.txt}
\subsection{a}
\subsection{b}
\clearpage
\section{B}
\begin{figure}[H] \caption{I} \end{figure}
\begin{figure}[H] \caption{II} \end{figure}
\begin{table} [H] \caption{I} \end{table}
\begin{table} [H] \caption{II} \end{table}
\lstinputlisting[caption=I] {I.txt}
\lstinputlisting[caption=II]{I.txt}
\subsection{a}
\subsection{b}
\clearpage
\section{C}
\begin{figure}[H] \caption{I} \end{figure}
\begin{figure}[H] \caption{II} \end{figure}
\begin{table} [H] \caption{I} \end{table}
\begin{table} [H] \caption{II} \end{table}
\lstinputlisting[caption=I] {I.txt}
\lstinputlisting[caption=II]{I.txt}
\subsection{a}
\subsection{b}
\end{appendices}
\end{document}