2

I am using the algorithm2e package to add some algorithms to my thesis with the following line in my preamble:

\usepackage[]{algorithm2e}

However, I am unable to add the list of algorithms to my table of contents. I get the following error message when I try to use \listofalgorithms

(./doc.loa
! Missing number, treated as zero.
<to be read again> 
                   \edef 
l.2 ...gnorespaces Simple Algorithm}}{1}{algocf.1}

I believe the issue is related to the use of these two files -- puthesis.cls and pulongtable.sty which I am required to use for my thesis. I have included a minimum working example below which throws the error when I run pdflatex on it twice.

Added by muzimuzi Z: To run the following example, you need to aquire notoccite.sty as well.

\documentclass[ece,bypass]{puthesis}
\usepackage{float}
\usepackage{hyperref}
\usepackage[]{algorithm2e}
\title{MWE}
\author{Zuko Aang}{Aang, Zuko}
\campus{Indianapolis}

\begin{document}
\volume

\listofalgorithms

\chapter{Hello}
\section{Test}
\begin{algorithm}[H]
  \caption{Simple Algorithm}
  Hello
  \label{alg:Simple Algorithm}
\end{algorithm}

\end{document}

Any help would be much appreciated. Thanks

2
  • 1
    Would you please provide an mwe so that others can use it as a start to help you? Commented May 21, 2020 at 6:49
  • Hi, I have added an mwe and more details as suggested. Thanks! Commented May 21, 2020 at 8:36

1 Answer 1

1

Solution

Redefine \l@algocf:

\documentclass[ece,bypass]{puthesis}
\usepackage{float}
\usepackage{algorithm2e}
\usepackage{hyperref}

\title{MWE}
\author{Zuko Aang}{Aang, Zuko}
\campus{Indianapolis}

\makeatletter
\renewcommand*\l@algocf{\@dottedtocline{1}{\smalltocskip}{1em}{2.3em}}
\makeatother

\begin{document}
\volume
\listofalgorithms

\chapter{Hello}
\section{Test}
\begin{algorithm}[H]
  \caption{Simple Algorithm}
  Hello
  \label{alg:Simple Algorithm}
\end{algorithm}

\end{document}

Explanation

In puthesis.cls, command \@dottedtocline is redefined to accept an extra argument as its new second argument. This #2 represents the extra vertical skip before every content item (e.g., a section in \tableofcontents or an algorithm \listofalgorithms). In puthesis.cls, \smalltocskip is passed to the #2 of \@dottedtocline in redefinition of commands like \l@section and \l@subsection. For example,

% before, in report.cls
\newcommand*\l@section{\@dottedtocline{1}{1.5em}{2.3em}}
\newcommand*\l@subsection{\@dottedtocline{2}{3.8em}{3.2em}}

% after, in puthesis.cls (comments are copied from puthesis.cls too)
% Got these lines using "grep dotted report.cls" and changed
% as needed for new \@dottedtocline \vskip parameter.
\renewcommand*\l@section{\@dottedtocline{1}{\smalltocskip}{1.5em}{2.3em}}
\renewcommand*\l@subsection{\@dottedtocline{2}{\smalltocskip}{3.8em}{3.2em}}

Hence, the solution is to redefine the internal command of an algorithm item in \listofalgorithms, which is \l@algocf, to sync with the change of \@dottedtocline.

% before, in algorithm2e.sty
% \newcommand*\l@algocf{\@dottedtocline{1}{1em}{2.3em}}

% after, in my answer
\renewcommand*\l@algocf{\@dottedtocline{1}{\smalltocskip}{1em}{2.3em}}
2
  • Thank you very much. That did the trick. I am very grateful. Btw, I did include links to puthesis.cls and pulongtable.sty as hyperlinks in the edited question. Is that not the correct way to include links? Commented May 21, 2020 at 10:08
  • @zuko I missed the links in your question. So sorry. Updated my answer. Commented May 21, 2020 at 10:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.