由于某种原因,我在工作中必须用 重新设置段落间距\setparsizes
。这在脚本的主要部分非常有效。但不幸的是,它也影响了算法列表。即使所有算法都在同一章中,条目之间也会增加一些额外的空间。
我不想有这种行为。这也很奇怪,因为 -command\setparsizes
既不影响表格列表也不影响目录,而只影响算法列表。
如何才能抑制索引中的额外空格,尤其是算法列表中的额外空格,同时保留\setparsizes
主要内容的 -command?也许可以进行一些分组?
这是我的 MWE:
\documentclass{scrreprt}
\usepackage{babel}
\usepackage[algochapter]{algorithm2e}
% This line causes the problem.
\setparsizes{0pt}{1\baselineskip plus .6\baselineskip minus .4\baselineskip}{0pt plus 1fil}
\begin{document}
\tableofcontents
\begingroup
\let\clearpage\relax
\listoftables
\listofalgorithms
\endgroup
% Some useless content
\chapter{First Chapter}
\begin{table}\caption{First table}\end{table}
\chapter{Second Chapter}
\section{Section 2.1}
\begin{table}\caption{Second table}\end{table}
\begin{algorithm}\caption{First algorithm}\end{algorithm}
\section{Section 2.2}
\begin{algorithm}\caption{Second algorithm}\end{algorithm}
\subsection{Subsection 2.2.1}
\begin{table}\caption{Third table}\end{table}
\begin{algorithm}\caption{Third algorithm}\end{algorithm}
\begin{table}\caption{Fourth table}\end{table}
\begin{algorithm}\caption{Fourth algorithm}\end{algorithm}
\subsection{Subsection 2.2.2}
\section{Section 2.3}
\end{document}
谢谢你!
答案1
我会用
\addtotoclist[float]{loa}
\renewcommand*\listofalgorithms{\listoftoc[\listalgorithmcfname]{loa}}
然后\listofalgorithms
受到KOMA-Script 包的控制tocbasic
。
为了确保使用相同的缩进和数字宽度:
\DeclareTOCStyleEntry[level:=figure,indent:=figure,numwidth:=figure]{tocline}{algocf}
请注意,语法level:
等至少需要 KOMA-Script 版本 3.27。
我还建议使用以下方法恢复 KOMA-Script 的章节定义
\RedeclareSectionCommand{chapter}
如果 LoF、LoT 和 LoA 确实应该是没有分页符的章节,则可以使用
\doforeachtocfile[float]{\BeforeTOCHead[#1]{\let\clearpage\relax}}
例子:
\documentclass{scrreprt}[2019/10/12]
\usepackage{babel}
\usepackage[algochapter]{algorithm2e}
\RedeclareSectionCommand{chapter}
\addtotoclist[float]{loa}
\renewcommand*\listofalgorithms{\listoftoc[\listalgorithmcfname]{loa}}
\DeclareTOCStyleEntry[level:=figure,indent:=figure,numwidth:=figure]{tocline}{algocf}
\doforeachtocfile[float]{\BeforeTOCHead[#1]{\let\clearpage\relax}}
% This line causes the problem.
\setparsizes{0pt}{1\baselineskip plus .6\baselineskip minus .4\baselineskip}{0pt plus 1fil}
\begin{document}
\tableofcontents
\listoftables
\listofalgorithms
% Some useless content
\chapter{First Chapter}
\begin{table}\caption{First table}\end{table}
\chapter{Second Chapter}
\section{Section 2.1}
\begin{table}\caption{Second table}\end{table}
\begin{algorithm}\caption{First algorithm}\end{algorithm}
\section{Section 2.2}
\begin{algorithm}\caption{Second algorithm}\end{algorithm}
\subsection{Subsection 2.2.1}
\begin{table}\caption{Third table}\end{table}
\begin{algorithm}\caption{Third algorithm}\end{algorithm}
\begin{table}\caption{Fourth table}\end{table}
\begin{algorithm}\caption{Fourth algorithm}\end{algorithm}
\subsection{Subsection 2.2.2}
\section{Section 2.3}
\end{document}
但我会使用选项listof=leveldown
。然后 LoF、LoT、LoA 等就是部分。因此无需重新定义\clearpage
。
例子:
\documentclass[listof=leveldown]{scrreprt}[2019/10/12]
\usepackage{babel}
\usepackage[algochapter]{algorithm2e}
\RedeclareSectionCommand{chapter}
\addtotoclist[float]{loa}
\renewcommand*\listofalgorithms{\listoftoc[\listalgorithmcfname]{loa}}
\DeclareTOCStyleEntry[level:=figure,indent:=figure,numwidth:=figure]{tocline}{algocf}
% This line causes the problem.
\setparsizes{0pt}{1\baselineskip plus .6\baselineskip minus .4\baselineskip}{0pt plus 1fil}
\begin{document}
\tableofcontents
\listoftables
\listofalgorithms
% Some useless content
\chapter{First Chapter}
\begin{table}\caption{First table}\end{table}
\chapter{Second Chapter}
\section{Section 2.1}
\begin{table}\caption{Second table}\end{table}
\begin{algorithm}\caption{First algorithm}\end{algorithm}
\section{Section 2.2}
\begin{algorithm}\caption{Second algorithm}\end{algorithm}
\subsection{Subsection 2.2.1}
\begin{table}\caption{Third table}\end{table}
\begin{algorithm}\caption{Third algorithm}\end{algorithm}
\begin{table}\caption{Fourth table}\end{table}
\begin{algorithm}\caption{Fourth algorithm}\end{algorithm}
\subsection{Subsection 2.2.2}
\section{Section 2.3}
\end{document}
答案2
您可以教\listofalgorithms
(实际上是内部版本\listofalgocfs
)使用\tocbasic@starttoc
(特定于scrreprt
)而不是标准\@starttoc
命令。
\documentclass{scrreprt}
\usepackage{babel}
\usepackage[algochapter]{algorithm2e}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\listofalgocfs}{\@starttoc}{\tocbasic@starttoc}{}{}
\makeatother
% This line causes the problem.
\setparsizes{0pt}{1\baselineskip plus .6\baselineskip minus .4\baselineskip}{0pt plus 1fil}
\begin{document}
\tableofcontents
\begingroup
\let\clearpage\relax
\listoftables
\listofalgorithms
\endgroup
% Some useless content
\chapter{First Chapter}
\begin{table}\caption{First table}\end{table}
\chapter{Second Chapter}
\section{Section 2.1}
\begin{table}\caption{Second table}\end{table}
\begin{algorithm}\caption{First algorithm}\end{algorithm}
\section{Section 2.2}
\begin{algorithm}\caption{Second algorithm}\end{algorithm}
\subsection{Subsection 2.2.1}
\begin{table}\caption{Third table}\end{table}
\begin{algorithm}\caption{Third algorithm}\end{algorithm}
\begin{table}\caption{Fourth table}\end{table}
\begin{algorithm}\caption{Fourth algorithm}\end{algorithm}
\subsection{Subsection 2.2.2}
\section{Section 2.3}
\end{document}