2

I'm trying to create a list of algorithms such that the a colon appears after every algorithm number. I've included a MWE below that produces the following,

enter image description here

I'd like to modify this by adding a colon after the algorithm number,

Algorithm 1.1: Pseudocode caption . . . . 2

I have seen similar questions asked (Formatting \listoftables and \listofalgorithms), however this solution does not work for me. I believe it is because their example uses algorithm while I am using algorithm2e. I haven't been able to solve this issue.

The "LIST OF ALGORITHMS" header needs to remain as it is shown in the MWE, I cannot have the default header that usually appears with \listofalgorithms

Minimum working example:

\documentclass[10pt]{report}

\usepackage[ruled,vlined,algochapter]{algorithm2e}  
\usepackage{tocloft}

\makeatletter
\newcommand*{\loacontents}{\@starttoc{loa}}
\makeatother

\begin{document}

\begingroup
\renewcommand*{\addvspace}[1]{}
\let\oldnumberline\numberline
\renewcommand{\numberline}{Algorithm~\oldnumberline}
\begin{center}
    \textbf{LIST OF ALGORITHMS}
\end{center}
~\\ % Empty lines
~\\
\loacontents
\endgroup

\pagebreak

\chapter{Introduction}
\begin{algorithm}
    \caption{Pseudocode caption.}
    asdf        
\end{algorithm}
\end{document}
1
  • 1
    Welcome to TeX.SE! – Mensch Dec 7 '18 at 20:13
3

A minor adjustment to the redefinition of \numberline. Instead, collect the regular argument, and add a : suffix when you pass that on to \oldnumberline:

enter image description here

\documentclass{report}

\usepackage[ruled,vlined,algochapter]{algorithm2e}  

\makeatletter
\newcommand*{\loacontents}{\@starttoc{loa}}
\makeatother

\begin{document}

\begingroup
\renewcommand*{\addvspace}[1]{}
\let\oldnumberline\numberline
\renewcommand{\numberline}[1]{Algorithm~\oldnumberline{#1:}}
\begin{center}
  \bfseries LIST OF ALGORITHMS
\end{center}
\vspace{2\baselineskip}
\loacontents
\endgroup

\pagebreak

\chapter{Introduction}
\begin{algorithm}
  \caption{Pseudocode caption.}
  asdf
\end{algorithm}

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