![图表列表中的部分标题?](https://linux22.com/image/265066/%E5%9B%BE%E8%A1%A8%E5%88%97%E8%A1%A8%E4%B8%AD%E7%9A%84%E9%83%A8%E5%88%86%E6%A0%87%E9%A2%98%EF%BC%9F.png)
我正在使用 KOMAScript。我有一个\listoffigures
和一个\listoftables
。我的文档有几个\part{}
。在这两个列表中,图表已经按章节分组(小的垂直空间)。
除了(“匿名”)章节空间分组之外,我还想在两个列表中的每个“部分组”的图表和表格上添加部分标题。这是否可以在无需从头开始编写列表的情况下实现?
答案1
您可以通过以下方式设置自己的条目:
\newcommand{\addtocentrylistof}[3]{%
\ifstr{#2}{}{%
\addcontentsline{lof}{#1}{#3}%
\addcontentsline{lot}{#1}{#3}%
}{%
\addcontentsline{lof}{#1}{\protect\numberline{#2}#3}%
\addcontentsline{lot}{#1}{\protect\numberline{#2}#3}%
}%
}
\renewcommand*{\addparttocentry}[2]{%
\addtocentrydefault{part}{#1}{#2}%
\addtocentrylistof{part}{#1}{#2}%
}
这里有一个小例子:
\documentclass[english]{scrreprt}
\usepackage{babel}
\newcommand{\addtocentrylistof}[3]{%
\ifstr{#2}{}{%
\addcontentsline{lof}{#1}{#3}%
\addcontentsline{lot}{#1}{#3}%
}{%
\addcontentsline{lof}{#1}{\protect\numberline{#2}#3}%
\addcontentsline{lot}{#1}{\protect\numberline{#2}#3}%
}%
}
\renewcommand*{\addparttocentry}[2]{%
\addtocentrydefault{part}{#1}{#2}%
\addtocentrylistof{part}{#1}{#2}%
}
\def\examplefig{\begin{figure}[!ht]\caption{foo}\end{figure}\begin{table}[!ht]\caption{foo}\end{table}}
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\part{O I}
\chapter{foo}
\examplefig\examplefig\examplefig
\chapter{foo}
\examplefig\examplefig\examplefig
\chapter{foo}
\examplefig\examplefig\examplefig
\part{O II}
\chapter{bar}
\examplefig\examplefig\examplefig
\chapter{bar}
\examplefig\examplefig\examplefig
\chapter{bar}
\examplefig\examplefig\examplefig
\end{document}
答案2
这只是改编自this answer
到是否在带有 titletoc 的图表列表中包含章节?。使用标准命令自动进行包含,并且仅针对带有图形的部分:
\documentclass{scrreprt}
\usepackage{etoolbox} % or xpatch
\makeatletter
% initial definitions of the chapter info (name and number)
\def\thischaptertitle{}\def\thischapternumber{}
\newtoggle{noFigs}
\newtoggle{noTabs}
\apptocmd{\@part}%
{\gdef\thisparttitle{#1}\gdef\thispartnumber{\thepart}%
\global\toggletrue{noFigs}\global\toggletrue{noTabs}}{}{}
% the figure environment does the job: the first time it is used after a \chapter command,
% it writes the information of the chapter to the LoF
\AtBeginDocument{%
\AtBeginEnvironment{figure}{%
\iftoggle{noFigs}{
\addtocontents{lof}{\protect\contentsline {part}%
{\protect\numberline {\thispartnumber} {\thisparttitle}}{}{} }
\global\togglefalse{noFigs}
}{}
}%
\AtBeginEnvironment{table}{%
\iftoggle{noTabs}{
\addtocontents{lot}{\protect\contentsline {part}%
{\protect\numberline {\thispartnumber} {\thisparttitle}}{}{} }
\global\togglefalse{noTabs}
}{}
}%
}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\part{Test Part With Figures and Tables}
\chapter{Test Chapter with Figures and Tables}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{table}
\caption{caption text for a table}
\end{table}
\part{Test Part with no Figures and no Tables}
\part{Test Part with no Figures and Tables}
\chapter{Test Chapter with Table}
\begin{table}
\caption{caption text for a table}
\end{table}
\part{Test Part with no Tables and Figures}
\chapter{Test Chapter with Figure}
\begin{figure}
\caption{caption text}
\end{figure}
\part{Another Test Part With Figures and Tables}
\chapter{Another Test Chapter}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{table}
\caption{caption text for a table}
\end{table}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{table}
\caption{caption text for a table}
\end{table}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\end{document}
LoF 的图像:
LoT 的图片: