3

For some reason, in my work I have to reset the spacing of paragraphs with \setparsizes. This works quite well in the main part of the skript. But unfortunatley, it also effects the list of algorithms. There is some extra space added between the entries, even all algorithms are in the same chapter.

enter image description here

I dont want to have this behaviour. It is also strange, because the \setparsizes-command does neither effect the list of tables nor the table of contents, but only the list of algorithms.

How can I suppress the extra spacing in the indices, especially in the list of algorithms, while keeping the \setparsizes-command for the main content? Maybe some grouping?

Here is my 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}

Thank you!

1

I would use

\addtotoclist[float]{loa}
\renewcommand*\listofalgorithms{\listoftoc[\listalgorithmcfname]{loa}}

Then \listofalgorithms is under controll of KOMA-Script package tocbasic.

To ensure that the same indent and number width is used:

\DeclareTOCStyleEntry[level:=figure,indent:=figure,numwidth:=figure]{tocline}{algocf}

Note, that the syntax level: etc. needs at least KOMA-Script version 3.27.

I would also suggest to restore the chapter definition of KOMA-Script using

\RedeclareSectionCommand{chapter}

If LoF, LoT and LoA should really be chapters without page break before them, you could use

\doforeachtocfile[float]{\BeforeTOCHead[#1]{\let\clearpage\relax}}

Example:

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

enter image description here

But I would use option listof=leveldown. Then the LoF, LoT, LoA etc. are sections. So there would be no need to redefine \clearpage.

Example:

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

enter image description here

2
  • Nice! :) But why the command \addtotoclist[float]{loa} is needed? It is also working without that line. – Till now, I didnt realize that there is some deviation in the indent^^ Thanks a lot! – Max16hr Jan 14 at 1:51
  • 1
    \addtotoclist[float]{loa} is needed, if the list of algorithms should take care of values of option listof=..., eg listof=leveldown or listof=totoc etc. – esdd Jan 14 at 15:56
2

You may teach \listofalgorithms (actually the internal version \listofalgocfs) to use \tocbasic@starttoc (specific for scrreprt) instead of the standard \@starttoc command.

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

enter image description here

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.