2
\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}

The table of contents produced is the following: Table of Contents with gap between entries in List of Algorithms

Namely, notice the chapter gap between the two entries under the List of Algorithms. This gap is absent from the entries in the List of Figures because of the listof=nochaptergap option that was specified in the preamble; however, the List of Algorithms does not seem to honor that option. Is there any way to fix that? Perhaps some argument to \setuptoc?

2

Package algorithm2e redefines the chapter command to add the additional space to the List of Algorithms. To disable this changes use

\RedeclareSectionCommand{chapter}

when package algorithm2e is loaded.

enter image description here

Code:

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.