2

I have to number the algorithms based on the chapters that they appear.

I have used the command \listofalgorithmes.

But still I have the issues. Please refer to the attached codes and figures

\documentclass[a4paper,11pt]{report}
\usepackage{tocbibind}
\newcommand{\listofalgorithmes}{\tocfile{\listalgorithmcfname}{loa}}
\usepackage[ansinew]{inputenc}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{etoolbox}
\newcounter{algoline}
\newcommand\Numberline{\refstepcounter{algoline}\nlset{\thealgoline}}
\AtBeginEnvironment{algorithm}{\setcounter{algoline}{0}}
\begin{document}
\listofalgorithmes

\chapter{Test}
\begin{algorithm} 
\caption{Algo A1}\label{alg:A1}
\end{algorithm}
\begin{algorithm} 
\caption{Algo A2}\label{alg:A2}
\end{algorithm}

 \chapter{Test2}
 \begin{algorithm} 
 \caption{Algo B1}\label{alg:B1}
\end{algorithm}
\begingroup
\LinesNumberedHidden
\begin{algorithm}
\DontPrintSemicolon
\KwIn{A,B,C }
\KwOut{D,E,F}
\Numberline\textbf{Step 1}\\ AAA.\;
BB, \\ee\; 
\Numberline Then go to the home \\
\Numberline\textbf{Step 2} \\
\Numberline BB,\\ cc\; 
\Numberline Then go to a hotel \\
\SetAlgoRefName{1}
\caption{Ala kanawa}
\label{algo:sj1}
\end{algorithm}
\endgroup

\chapter{Test3}
\begin{algorithm} 
\caption{Algo C}\label{alg:C}
\end{algorithm}

\end{document}

enter image description here

2

Add the option algochapter to algorithm2e

\documentclass[a4paper,11pt]{report}
\usepackage{tocbibind}
\newcommand{\listofalgorithmes}{\tocfile{\listalgorithmcfname}{loa}}
\usepackage[ansinew]{inputenc}
\usepackage[linesnumbered,ruled,vlined,algochapter]{algorithm2e}
\usepackage{etoolbox}
\newcounter{algoline}
\newcommand\Numberline{\refstepcounter{algoline}\nlset{\thealgoline}}
\AtBeginEnvironment{algorithm}{\setcounter{algoline}{0}}
\begin{document}
\listofalgorithmes

\chapter{Test}
\begin{algorithm}
\caption{Algo A1}\label{alg:A1}
\end{algorithm}
\begin{algorithm}
\caption{Algo A2}\label{alg:A2}
\end{algorithm}

 \chapter{Test2}
 \begin{algorithm}
 \caption{Algo B1}\label{alg:B1}
\end{algorithm}
\begingroup
\LinesNumberedHidden
\begin{algorithm}
\DontPrintSemicolon
\KwIn{A,B,C }
\KwOut{D,E,F}
\Numberline\textbf{Step 1}\\ AAA.\;
BB, \\ee\;
\Numberline Then go to the home \\
\Numberline\textbf{Step 2} \\
\Numberline BB,\\ cc\;
\Numberline Then go to a hotel \\
%\SetAlgoRefName{1}          %% do you really need this?
\caption{Ala kanawa}
\label{algo:sj1}
\end{algorithm}
\endgroup

\chapter{Test3}
\begin{algorithm}
\caption{Algo C}\label{alg:C}
\end{algorithm}

\end{document}

enter image description here

|improve this answer|||||

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.