如果没有图形,并且每个章节都有颜色,我想从 LOF 中删除单词章节,表格也一样。
\documentclass{memoir}
\usepackage{lipsum}
\usepackage{etoolbox}
\renewcommand*{\insertchapterspace}{%
\addtocontents{lof}{\protect\addvspace{10pt}}%
\addtocontents{lot}{\protect\addvspace{10pt}}
\addtocontents{lof}{\protect\lofchapter{\thechapter}}%
\addtocontents{lot}{\protect\lofchapter{\thechapter}}%
}
\newcommand{\lofchapter}[1]{%
\noindent
\rule[.5ex]{.4\linewidth}{.2ex}\hfill
\textsc{Chapter #1}\hfill
\rule[.5ex]{.4\linewidth}{.2ex}\par
\nobreak
}
\newcommand{\lotchapter}[1]{%
\noindent
\rule[.5ex]{.4\linewidth}{.2ex}\hfill
\textsc{Chapter #1}\hfill
\rule[.5ex]{.4\linewidth}{.2ex}\par
\nobreak
}
\renewcommand*{\cftfigurename}{Figure\space} %<<<<<<<<<<<<<<<<<<<<
\renewcommand*{\cfttablename}{Table\space} %<<<<<<<<<<<<<<<<<<<<
\begin{document}
\sloppy% Just for this example
\listoffigures
\listoftables
\chapter{First chapter}
\lipsum[1-10]\begin{figure}\caption{First figure}\end{figure}
\begin{table}\caption{First figure}\end{table}
\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}
\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
这会将每章的图表总数存储在辅助文件中,但需要\savetotal
在每章结束时运行。您可以修改\chapter
并使用\AtEndDocument
,但那将是“懒人的负担”。
首先你需要构造一个颜色列表。最简单的方法是使用\ifcase
(参见 Knuth电子书第210页)。
\documentclass{memoir}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{etoolbox}
\newcommand{\colorlist}[1]% list index 0,1,...
{\ifcase#1\relax black\or blue\or red\or green\or yellow\or orange\or purple\else black\fi}% no space after color
\newcommand{\chaptercolor}{black}% reserve global name
\makeatletter
\newcommand{\savetotal}{\protected@write {\@auxout}{}{\string\xdef\string\totalfigures\roman{chapter}{\arabic{figure}}}%
\protected@write {\@auxout}{}{\string\xdef\string\totaltables\roman{chapter}{\arabic{table}}}}
\renewcommand*{\insertchapterspace}{\bgroup
\@ifundefined{totalfigures\roman{chapter}}{%
\addtocontents{lof}{\protect\addvspace{10pt}}%
\addtocontents{lof}{\protect\lofchapter{\thechapter}}%
}{\count1=\csname totalfigures\roman{chapter}\endcsname\relax
\the\count1
\ifnum\count1>0
\addtocontents{lof}{\protect\addvspace{10pt}}%
\addtocontents{lof}{\protect\lofchapter{\thechapter}}%
\fi}
\@ifundefined{totaltables\roman{chapter}}{%
\addtocontents{lot}{\protect\addvspace{10pt}}
\addtocontents{lot}{\protect\lotchapter{\thechapter}}%
}{\count1=\csname totaltables\roman{chapter}\endcsname\relax
\ifnum\count1>0
\addtocontents{lot}{\protect\addvspace{10pt}}
\addtocontents{lot}{\protect\lotchapter{\thechapter}}%
}%
\egroup}
\makeatother
\newcommand{\lofchapter}[1]{%
\xdef\chaptercolor{\colorlist#1}% see \cftfigurename
\noindent\textcolor{\chaptercolor}{%
\rule[.5ex]{.4\linewidth}{.2ex}\hfill
\textsc{Chapter #1}\hfill
\rule[.5ex]{.4\linewidth}{.2ex}}%
}
\newcommand{\lotchapter}[1]{%
\xdef\chaptercolor{\colorlist#1}% see \cfttablename
\noindent\textcolor{\chaptercolor}{%
\rule[.5ex]{.4\linewidth}{.2ex}\hfill
\textsc{Chapter #1}\hfill
\rule[.5ex]{.4\linewidth}{.2ex}}
}
\renewcommand*{\cftfigurename}{\textcolor{\chaptercolor}{Figure\space}}%<<<<<<<<<<<<<<<<<<<<
\renewcommand*{\cfttablename}{\textcolor{\chaptercolor}{Table\space}} %<<<<<<<<<<<<<<<<<<<<
\begin{document}
\sloppy% Just for this example
\listoffigures
\listoftables
\chapter{First chapter}
\lipsum[1-10]\begin{figure}\caption{First figure}\end{figure}
\begin{table}\caption{First table}\end{table}
\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]
\savetotal
\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]
\savetotal
\chapter{Third chapter}
\savetotal
\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]
\savetotal
\end{document}