\documentclass[oneside]{scrbook}
\KOMAoptions{%
toc=listof,
listof=leveldown,
listof=nochaptergap,
}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[babel]{microtype}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[algochapter]{algorithm2e}
\usepackage{graphicx}
\usepackage{hyperref}
\newcommand*{\NN}{\ensuremath{\mathbb{N}}}
\begin{document}
\addtotoclist[algorithm2e]{loa}
\setuptoc{loa}{%
chapteratlist, totoc, leveldown%
}
\newcommand*{\listofloaname}{\listalgorithmcfname}
\renewcommand{\listofalgorithms}{\listoftoc{loa}}
\frontmatter
\tableofcontents
\listoffigures
\listofalgorithms
\mainmatter%
\chapter{First}
\begin{figure}[h]
\begin{center}
\includegraphics[width=.5\textwidth]{example-image-a}
\caption{Example Image A}
\end{center}
\end{figure}
\begin{algorithm}
\caption{Algorithm for Computing \(n!\)}
\DontPrintSemicolon{}
\KwIn{\(n \in \NN\)}
\KwOut{\(n!\)}
\Begin{%
\uIf{\(n = 0\)}{%
\Return{\(1\)}%
}
\Else{%
\Return{\(\prod_{k = 1}^{n} k\)}%
}
}
\end{algorithm}
\chapter{Second}
\begin{figure}[h]
\begin{center}
\includegraphics[width=.5\textwidth]{example-image-b}
\caption{Example Image B}
\end{center}
\end{figure}
\begin{algorithm}
\caption{Another Algorithm for Computing \(n!\)}
\DontPrintSemicolon{}
\KwIn{\(n \in \NN\)}
\KwOut{\(n!\)}
\Begin{%
\uIf{\(n = 0\)}{%
\Return{\(1\)}%
}
\Else{%
\Return{\(\prod_{k = 1}^{n} k\)}%
}
}
\end{algorithm}
\backmatter%
\end{document}
也就是说,请注意算法列表. 此项空白在图片列表因为listof=nochaptergap
序言中指定的选项;然而,算法列表似乎不尊重该选项。有什么办法可以解决这个问题吗?也许可以对 进行一些争论\setuptoc
?
答案1
软件包algorithm2e
重新定义了章节命令,以将额外的空间添加到算法列表中。要禁用此更改,请使用
\RedeclareSectionCommand{chapter}
当包algorithm2e
被加载时。
代码:
\documentclass[oneside]{scrbook}
\KOMAoptions{%
toc=listof,
listof=leveldown,
listof=nochaptergap,
}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[babel]{microtype}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[algochapter]{algorithm2e}
\RedeclareSectionCommand{chapter}% <- added
\usepackage{graphicx}
\usepackage{hyperref}
\newcommand*{\NN}{\ensuremath{\mathbb{N}}}
\addtotoclist[algorithm2e]{loa}
\setuptoc{loa}{%
chapteratlist,totoc, leveldown%
}
\newcommand*{\listofloaname}{\listalgorithmcfname}
\renewcommand{\listofalgorithms}{\listoftoc{loa}}
\begin{document}
\frontmatter
\tableofcontents
\listoffigures
\listofalgorithms
\mainmatter%
\chapter{First}
\begin{figure}[h]
\begin{center}
\includegraphics[width=.5\textwidth]{example-image-a}
\caption{Example Image A}
\end{center}
\end{figure}
\begin{algorithm}
\caption{Algorithm for Computing \(n!\)}
\DontPrintSemicolon{}
\KwIn{\(n \in \NN\)}
\KwOut{\(n!\)}
\Begin{%
\uIf{\(n = 0\)}{%
\Return{\(1\)}%
}
\Else{%
\Return{\(\prod_{k = 1}^{n} k\)}%
}
}
\end{algorithm}
\chapter{Second}
\begin{figure}[h]
\begin{center}
\includegraphics[width=.5\textwidth]{example-image-b}
\caption{Example Image B}
\end{center}
\end{figure}
\begin{algorithm}
\caption{Another Algorithm for Computing \(n!\)}
\DontPrintSemicolon{}
\KwIn{\(n \in \NN\)}
\KwOut{\(n!\)}
\Begin{%
\uIf{\(n = 0\)}{%
\Return{\(1\)}%
}
\Else{%
\Return{\(\prod_{k = 1}^{n} k\)}%
}
}
\end{algorithm}
\backmatter%
\end{document}