在我的論文中,我在最後有一些 R 腳本,作為附錄。在附錄本身中,我想要\lstlistoflistings
.
這會將清單格式化為章節(與目錄相同)。
如何將其格式化為節?我只是想避免章節標題後面的分頁符,並在其後面列出列表,並使用較小的字體。
這是一個最小的工作範例
\documentclass{report}
\usepackage{listings}
\lstset{language=R}
\renewcommand{\lstlistlistingname}{List of R scripts}
\begin{document}
\tableofcontents
\chapter{the first chapter}
\section{section1}
some text
\chapter{the second chapter}
\addcontentsline{toc}{chapter}{Appendix A}
\chapter*{Appendix A}
\lstlistoflistings
\newpage
\begin{lstlisting}[caption=A script]
some code
\end{lstlisting}
\begin{lstlisting}[caption=Another script]
some more code
\end{lstlisting}
\end{document}
謝謝!
答案1
您可以加載tocbasic
和scrhack
.然後你可以使用\setuptoc{lol}{leveldown}
:
\documentclass{report}
\usepackage{scrhack}
\usepackage{tocbasic}
\setuptoc{lol}{leveldown}
\usepackage{listings}
\lstset{language=R}
\renewcommand{\lstlistlistingname}{List of R scripts}
\begin{document}
\tableofcontents
\chapter{the first chapter}
\section{section1}
some text
\chapter{the second chapter}
\chapter*{Appendix A}
\addcontentsline{toc}{chapter}{Appendix A}
\lstlistoflistings
\newpage
\begin{lstlisting}[caption=A script]
some code
\end{lstlisting}
\begin{lstlisting}[caption=Another script]
some more code
\end{lstlisting}
\end{document}
\chapter*
我更改了和的順序\addcontentsline
,以獲得目錄中正確的頁碼。
答案2
\lstlistoflistings
(多麼容易記住的名字啊;-))\tableofcontents
實際上在內部使用並\@starttoc
稍微重新定義以應用,但仍然有\chapter*
標題\tableofcontents
。
在我看來,更容易應用 的重新定義,\lstlistoflistings
使其具有與 相同的外觀\tableofcontents
。
\documentclass{report}
\usepackage{listings}
\lstset{language=R}
\renewcommand{\lstlistlistingname}{List of R scripts}
\makeatletter
\renewcommand{\lstlistoflistings}{%
\begingroup
\clearpage
\section*{\lstlistlistingname% Taken from `article.cls`....
\@mkboth{%
\MakeUppercase\lstlistlistingname}{\MakeUppercase
\lstlistlistingname}
}%
\@starttoc{lol}
\endgroup
}
\makeatother
\begin{document}
\tableofcontents
\chapter{the first chapter}
\section{section1}
some text
\chapter{the second chapter}
\addcontentsline{toc}{chapter}{Appendix A}
\chapter*{Appendix A}
\lstlistoflistings
\newpage
\begin{lstlisting}[caption=A script]
some code
\end{lstlisting}
\begin{lstlisting}[caption=Another script]
some more code
\end{lstlisting}
\end{document}