2

I would like to have two environments sharing a counter and appearing in the same list. One of these environments is algorithm2e and the other is a simple frame for holding algorithms I want to typeset in another way. The following code gets both environments to appear in the same list of algorithms, but their numbering doesn't match and the formatting for each line in the list of algorithms does not match.

Here is the code I have so far:

\documentclass{book}
\usepackage[lined,vlined,linesnumbered,algochapter,ruled]{algorithm2e} 
\newcommand{\listofalgorithmes}{\tocfile{\listalgorithmcfname}{loa}}
\usepackage{float}
\newfloat{framealgorithm}{tbp}{loa}[chapter]
\floatname{framealgorithm}{Algorithm}
\makeatletter
\let\c@foo\c@algorithm
\renewcommand{\fnum@framealgorithm}{{\bf  Algorithm~\theframealgorithm}\linespacing{1}}
\newcommand{\l@framealgorithm}{\@dottedtocline{1}{1.5em}{2.3em}}
\makeatother

\begin{document}
\listofalgorithms
\begin{algorithm}
Hello world!
\caption{Algorithm}
\end{algorithm}

\begin{framealgorithm}
Hello world from a Frame
\caption{Frame Algorithm}
\end{framealgorithm}

\end{document}

and here is the output output of code

0

1 Answer 1

2

The aliascnt package was used to make one of the counters an alias for the other. Since algorithm2e uses

\newcommand*\l@algocf{\@dottedtocline{1}{1em}{2.3em}}%

then you have to use the same settings for your float

\newcommand\l@framealgorithm{\@dottedtocline{1}{1em}{2.3em}}

Or change \l@algocf to use 1.5em.

A complete example:

\documentclass{book}
\usepackage{aliascnt}
\usepackage[lined,vlined,linesnumbered,algochapter,ruled]{algorithm2e} 
\usepackage{float}

\newcommand\listofalgorithmes{%
  \tocfile{\listalgorithmcfname}{loa}}

\newfloat{framealgorithm}{thbp}{loa}[chapter]
\floatname{framealgorithm}{Algorithm}

\makeatletter
\renewcommand\fnum@framealgorithm{%
  {\bfseries  Algorithm~\theframealgorithm}}
\newcommand\l@framealgorithm{\@dottedtocline{1}{1em}{2.3em}}
\let\c@framealgorithm\relax
\newaliascnt{framealgorithm}{\algocf@float}
\makeatother

\begin{document}
\listofalgorithms

\begin{algorithm}
Hello world!
\caption{Algorithm}
\end{algorithm}

\begin{framealgorithm}
Hello world from a Frame
\caption{Frame Algorithm}
\end{framealgorithm}

\begin{algorithm}
Hello world!
\caption{Algorithm two}
\end{algorithm}

\begin{framealgorithm}
Hello world from a Frame
\caption{Another frame Algorithm}
\end{framealgorithm}

\end{document}

An image of the first page:

enter image description here

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.