我希望在算法列表中为插入的每一章留出空间,类似于在图表列表和表格列表中出现的方式。
这是我的代码:
\documentclass{book}
\usepackage{lipsum}
\usepackage{listings}
\usepackage{tocloft}
\renewcommand{\lstlistingname}{Algoritmo}% Listing -> Algorithm
\renewcommand{\lstlistlistingname}{Indice de \lstlistingname s}% List of Listings -> List of Algorithms
\begin{document}
\tableofcontents
\lstlistoflistings
%\listofmyequations
\chapter{A chapter}
\section{First section}
\medskip
\begin{lstlisting}[language=Java,escapechar=|,caption= Algoritmo hiperparametros]
x=a+b
};
\end{lstlisting}
[lipsum]
\medskip
\begin{lstlisting}[language=Java,escapechar=|,caption= Algoritmo hiperparametros]
x=a+b
};
\end{lstlisting}
\chapter{second chapter}
\section{First section}
\medskip
\begin{lstlisting}[language=Java,escapechar=|,caption= Algoritmo hiperparametros]
x=a+b
};
\end{lstlisting}
我希望它看起来像这个例子,但对于我的算法:
答案1
每次致电\chapter
,book
班级通过间接调用在 LoF 和 LoT 中插入空格\@chapter
:
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\thechapter}#1}%
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\chaptermark{#1}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\@afterheading
\fi}
注意呼叫
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
插入到和文件\addvspace{10\p@}
中。您需要做的就是插入.lof
.lot
\addtocontents{lol}{\protect\addvspace{10\p@}}%
在(列表列表)中添加相同的空间.lol
。这可以通过补丁来实现\@chapter
(感谢etoolbox
):
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@chapter}% <cmd>
{\addtocontents}% <search>
{\addtocontents{lol}{\protect\addvspace{10\p@}}% Add per-chapter space in LoL
\addtocontents}% <replace>
{}{}% <success><failure>
\makeatother