# How to reinitialize the lines counter for algorithms?

I have four algorithms in a section but the problem is that the lines numbering doesn't start with 1 in each algorithm. For example, the first one is numbered from 1 to 11 but the second one start with line number 12 rather than 1. I want to know how can I reinitialize the lines counter for each algorithm to have lines numbers starting with 1?

Here is my code:

\documentclass[letterpaper,12pt,oneside,final]{book}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage[ruled,algo2e,french]{algorithm2e}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{pdfpages}
\usepackage{epstopdf}
\usepackage{amsmath,color,soulutf8,longtable,colortbl,setspace,ifthen,xspace,url,pdflscape}
\makeatletter
\usepackage[frenchb]{babel}
\usepackage{caption}
\begin{document}
\begin{algorithm}[H]
\SetKwInput{Initialization}{Initialisation}
\LinesNumbered
\Initialization{}
\For{}{}
\end{algorithm}
\begin{algorithm}[h]
\SetKwInput{Initialization}{Initialisation}
\LinesNumbered
\Initialization{}
\For{}{}
\end{algorithm}
\end{document}

• related: tex.stackexchange.com/questions/86715/…. Also: please provide a complete code example (Minimal Working Example, MWE) to show the problem, this makes it easier to offer solutions. – Marijn May 27 '16 at 15:03
• You can edit your post and paste it in your original post. Without that information, there's not really anything we can do. – Werner May 27 '16 at 16:18
• I tried the command \setcounter{ALG@line}{1} but It didn't change any thing. – Pawla May 27 '16 at 16:37

Use this simple code: \setcounter{AlgoLine}{<number>}. The Alg@line is incorrect. You should use Algoline

\begin{algorithm}[H]
\SetKwInput{Initialization}{Initialisation}
\LinesNumbered
\Initialization{}
\For{}{}
\end{algorithm}
\begin{algorithm}[h]
\setcounter{AlgoLine}{0}
\SetKwInput{Initialization}{Initialisation}
\LinesNumbered
\Initialization{}
\For{}{}
\end{algorithm}


You can't mix the use of the algorithms bundle (which provides an algorithm environment/float) with algorithm2e. Use either the one, or the other.

\documentclass{article}

\usepackage[ruled]{algorithm2e}

\begin{document}

\begin{algorithm}[H]
\SetKwInput{Initialization}{Initialisation}
\LinesNumbered
\Initialization{}
\For{}{}
\end{algorithm}

\begin{algorithm}[h]
\SetKwInput{Initialization}{Initialisation}
\LinesNumbered
\Initialization{}
\For{}{}
\end{algorithm}

\end{document}


Note that since you're only using algorithm2e interface, there's no need to use the algo2e package option.

If you must use them together, for whatever reason, you need to use the algo2e package option and explicitly set algorithm2e-style algorithms inside an algorithm2e environment, and algorithmicx-style algorithms inside an algorithm environment.