我想将以下代码从报告类转换为回忆录类,并在图中显示相同的结果
\documentclass{report}
\usepackage{lipsum}
\usepackage{etoolbox}
\makeatletter
% Update \@chapter to insert the chapter ornament in the LoF
\patchcmd{\@chapter}% <cmd>
{\addtocontents{lof}{\protect\addvspace{10\p@}}}% <search>
{\addtocontents{lof}{%
\protect\addvspace{10\p@}% Default space between chapters in LoF
\protect\lofchapter{\thechapter}% Add chapter ornament
}}% <replace>
{}{}% <success><failure>
\makeatother
\newcommand{\lofchapter}[1]{%
\noindent
\rule[.5ex]{.4\linewidth}{.2ex}\hfill
\textsc{Chapter #1}\hfill
\rule[.5ex]{.4\linewidth}{.2ex}\par
\nobreak
}
\begin{document}
\sloppy% Just for this example
\listoffigures
\chapter{First chapter}
\lipsum[1-10]\begin{figure}\caption{First figure}\end{figure}
\lipsum[11-20]\begin{figure}\caption{Second figure}\end{figure}
\lipsum[21-30]\begin{figure}\caption{Third figure}\end{figure}
\lipsum[31-40]\begin{figure}\caption{Last figure}\end{figure}
\lipsum[41-50]
\chapter{Second chapter}
\lipsum[1-10]\begin{figure}\caption{First figure}\end{figure}
\lipsum[11-20]\begin{figure}\caption{Second figure}\end{figure}
\lipsum[21-30]\begin{figure}\caption{Third figure}\end{figure}
\lipsum[31-40]\begin{figure}\caption{Last figure}\end{figure}
\lipsum[41-50]
\chapter{Third chapter}
\lipsum[1-10]\begin{figure}\caption{First figure}\end{figure}
\lipsum[11-20]\begin{figure}\caption{Second figure}\end{figure}
\lipsum[21-30]\begin{figure}\caption{Third figure}\end{figure}
\lipsum[31-40]\begin{figure}\caption{Last figure}\end{figure}
\lipsum[41-50]
\chapter{Last chapter}
\lipsum[1-10]\begin{figure}\caption{First figure}\end{figure}
\lipsum[11-20]\begin{figure}\caption{Second figure}\end{figure}
\lipsum[21-30]\begin{figure}\caption{Third figure}\end{figure}
\lipsum[31-40]\begin{figure}\caption{Last figure}\end{figure}
\lipsum[41-50]
\end{document}
答案1
使用回忆录很容易,只需用以下代码替换补丁即可
\renewcommand*{\insertchapterspace}{%
\addtocontents{lof}{\protect\addvspace{10pt}}%
\addtocontents{lot}{\protect\addvspace{10pt}}
\addtocontents{lof}{\protect\lofchapter{\thechapter}}%
%\addtocontents{lot}{\protect\lofchapter{\thechapter}}%
}
或者更简单,因为 memoir 自动加载 etoolbox
\apptocmd\insertchapterspace{%
\addtocontents{lof}{\protect\lofchapter{\thechapter}}%
}{}{}