2

When generating list of algorithms, the command \listofalgorithms automatically inserts a 10pt vspace after the last algorithm caption in a chapter. I need to remove this vertical space in such a way that all algorithms in all chapters align vertically similar.

1
  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Apr 7, 2015 at 22:21

1 Answer 1

3

This stems from a redefinition of \@chapter by algorithm2e:

\begingroup\expandafter\expandafter\expandafter\endgroup 
\expandafter\ifx\csname @chapter\endcsname\relax\else 
  \let\algocf@original@chapter=\@chapter% 
  \def\@chapter[#1]#2{\algocf@original@chapter[#1]{#2}\addtocontents{loa}{\protect\addvspace{10\p@}}}% 
\fi

It stores \@chapter and then redefines it to \addvspace{10\p@} similar to the traditional way chapters inserts spaces between figures/tables in the LoF/LoT.

To avoid this, load algorithm2e in the following way:

\makeatletter
\let\old@chapter\@chapter% Store \@chapter
\usepackage[<opts>]{algorithm2e}
\let\@chapter\old@chapter% Restore \@chapter
\makeatother

Here's a minimal example without the above code:

enter image description here

...and with:

enter image description here

\documentclass{report}
\makeatletter
\let\old@chapter\@chapter% Store \@chapter
\usepackage{algorithm2e}
\let\@chapter\old@chapter% Restore \@chapter
\makeatother
\begin{document}
\listofalgorithms
\chapter{First chapter}
\begin{algorithm}\caption{An algorithm}\end{algorithm}
\begin{algorithm}\caption{An algorithm}\end{algorithm}
\chapter{Second chapter}
\begin{algorithm}\caption{An algorithm}\end{algorithm}
\begin{algorithm}\caption{An algorithm}\end{algorithm}
\chapter{Last chapter}
\begin{algorithm}\caption{An algorithm}\end{algorithm}
\begin{algorithm}\caption{An algorithm}\end{algorithm}
\end{document}

Comment out the additions and recompile twice to switch between the two.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .