# Start line numbers in algorithm with 5

Is there a possibility to start the line numbers in an algorithm with 5? I want to show that in Algorithm 2 only Step 5 and 6 of Algorithm 1 are replaced by something else. I use the algorithm2e-package. Thanks!

\documentclass[12pt,a4paper]{article}

\usepackage{amssymb}

\usepackage[vlined,linesnumbered,ruled,resetcount]{algorithm2e}

\begin{document}
\LinesNotNumbered
\begin{algorithm}[H]
\caption{Algorithm Changes}

Compute $\theta=\max_i|y_i^{(k+1)}-\left[y_i^{(k+1)}\right]|$ and \\ $p:=\frac{\ln(||d^{(k)}||_\infty)}{\ln(||d^{(k-1)}||_\infty)}$. \\

\uIf{$\theta>\tau$ or ($p>1.5$ and $||d^{(k)}||_\infty<\theta$)}{Choose $y_i^{(k+1)}\notin\mathbb{Z}$ and branch.}

\end{algorithm}
\end{document}


In front of "Compute" and the If-Statement should come the line numbers 5 and 6.

• Could you please provide a minimal working example (MWE) that starts with \documentclass and ends at \end{document}. Oct 26, 2017 at 12:02
• I repeat: That starts with \documentclass and ends at \end{document}. An MWE should be compilable (if it doesn't show an error because of which the document isn't compilable anymore). Oct 26, 2017 at 12:48

You can use \setcounter{AlgoLine}{<number>} to set the line number manually:

\documentclass[12pt,a4paper]{article}

\usepackage{amssymb}

\usepackage[vlined,linesnumbered,ruled,resetcount]{algorithm2e}

\begin{document}
\LinesNotNumbered
\begin{algorithm}[H]
\caption{Algorithm Changes}
\setcounter{AlgoLine}{4}

\nl Compute $\theta=\max_i|y_i^{(k+1)}-\left[y_i^{(k+1)}\right]|$ and \\ $p:=\frac{\ln(||d^{(k)}||_\infty)}{\ln(||d^{(k-1)}||_\infty)}$. \\

\nl \uIf{$\theta>\tau$ or ($p>1.5$ and $||d^{(k)}||_\infty<\theta$)}{Choose $y_i^{(k+1)}\notin\mathbb{Z}$ and branch.}

\end{algorithm}
\end{document}


• @Charlotte you might accept my answer then (if you think enough time has passed and you won't get better answers). Oct 26, 2017 at 17:47
• also works with -1, so the lines are numbered from zero. Not sure if other negative integers work as well Mar 15, 2020 at 17:55