4

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.

2
  • 1
    Could you please provide a minimal working example (MWE) that starts with \documentclass and ends at \end{document}.
    – Skillmon
    Oct 26 '17 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).
    – Skillmon
    Oct 26 '17 at 12:48
6

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}

enter image description here

2
  • @Charlotte you might accept my answer then (if you think enough time has passed and you won't get better answers).
    – Skillmon
    Oct 26 '17 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 '20 at 17:55

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.