5

I'm writing my thesis and I have a few algorithms (using algorithm2e) that I want to list in my appendix, but I don't want to start a new page. Also my listoffigures currently creates a section, not a chapter, same for my bibliography.

Therefore I want to do the same for listofalgorithms, but I can't change it correctly. This is how the figure list is changed:

\renewcommand{\listoffigures}{%
  \@cfttocstart
  \par
  \begingroup
    \parindent\z@ \parskip\cftparskip
    \section{\listfigurename}
    \@starttoc{lof}%
  \endgroup
  \@cfttocfinish%
}%

I have tried not changing it from chapter to section, but change the layout of the chapter to section, but I can't get it perfectly, because I can't change the skip distance after the heading.

This is what almost looks right:

\renewcommand\listalgorithmcfname{\thesection\hspace{3mm}List of Algorithms}
\begingroup
    \let\cleardoublepage\relax  % book
    \let\clearpage\relax        % report
    \titleformat{\chapter} [hang] {\Large\bfseries\sffamily} {\thesection} {1em} {}
    \listofalgorithms
\endgroup

I tried suggestions of similar threads, but they use other algorithm packages, so I think the algorithm2e handles things in some different manner.

Any help is appreciated.

Edit: @Werner: I can't tell you why, but it's not working. Maybe it isn't in fact using a chapter, I'm not sure. It starts on a new page and the indent is the same as chapter headers.

This is a MWE:

\documentclass{report}
\usepackage{algorithm2e}
\begin{document}
\begin{algorithm}
    \caption{Algorithm}
\end{algorithm}

\listofalgorithms
\end{document}
2

I had the same problem and found no solution online, so I opened algorithm2e.sty and dug in. There is actually an undocumented feature to do just that.

I just intended to C-s'd for "chapter" in the whole file until I found something interesting, and I did:

\ifx\l@chapter\undefined\let\algocf@seclistalgo=\section\else\let\algocf@seclistalgo=\chapter\fi
% /!\ this is not part of the solution, it just explains how I found it.

So this means that writing

\makeatletter
\let\l@chapter=\undefined
\makeatother

before calling \usepackage[…]{algorithm2e} will nicely do the trick :).

Another solution is to directly call \@starttoc, knowing that the list of algorithms is toc loa:

\section*{List of Algorithms} % or whatever is preferred
\makeatletter
\@starttoc{loa}
\makeatother
1

Easiest would be to let \chapter be equivalent to \section:

\begingroup
\let\chapter\section% Make \chapter equivalent to \section
\listofalgorithms
\endgroup

The \chapter update is temporary until \listofalgorithms is complete.

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.