algoritmo, como iniciar a numeração de linhas em determinado número (usando algoritmo2e)

algoritmo, como iniciar a numeração de linhas em determinado número (usando algoritmo2e)

Gostaria de saber como iniciar um código em um número específico; isso é necessário quando o algoritmo é dividido em duas páginas.

Um pequeno exemplo que gostaria de começar na linha 39 em vez da linha 1. Existe uma maneira de fazer isso?

\documentclass[paper=a4,toc=bibliography,nonchapterprefix,parskip=true]{scrreprt}

\usepackage[linesnumbered]{algorithm2e}

\begin{document}

\IncMargin{1em}
\begin{algorithm}
  \SetKwData{Left}{left}
  \SetKwData{Up}{up}
  \SetKwFunction{FindCompress}{FindCompress}
  \SetKwInOut{Input}{input}
  \SetKwInOut{Output}{output}

 \Indm
 \Input{A bitmap $Im$ of size $w\times l$}
 \Output{A partition of the bitmap}
\Indp
\BlankLine
  \For{$i\leftarrow 2$ \KwTo $l$}{
    \Left$\leftarrow$ \FindCompress{$Im[i,j-1]$}\;
    \Up$\leftarrow$ \FindCompress{$Im[i-1,]$}\; }
    \lForEach{element $e$ of the line $i$}{\FindCompress{p}}
\end{algorithm}
\DecMargin{1em}

atenciosamente!

Responder1

O algorithm2epacote tem uma noresetcountopção, mas isso tem o efeito de numerar todos os algoritmos continuamente.

Você pode definir uma \rememberlinesmacro que armazenará o número da linha atual no final de um algorithmambiente e uma \resumenumberingmacro que utilize esse valor.

\documentclass[paper=a4,toc=bibliography,parskip=true]{scrreprt}

\usepackage[linesnumbered]{algorithm2e}

\newcommand{\rememberlines}{\xdef\rememberedlines{\number\value{AlgoLine}}}
\newcommand{\resumenumbering}{\setcounter{AlgoLine}{\rememberedlines}}

\begin{document}

\IncMargin{1em}
\begin{algorithm}
  \SetKwData{Left}{left}
  \SetKwData{Up}{up}
  \SetKwFunction{FindCompress}{FindCompress}
  \SetKwInOut{Input}{input}
  \SetKwInOut{Output}{output}

  \Indm
  \Input{A bitmap $Im$ of size $w\times l$}
  \Output{A partition of the bitmap}
  \Indp
  \BlankLine
  \For{$i\leftarrow 2$ \KwTo $l$}{
    \Left$\leftarrow$ \FindCompress{$Im[i,j-1]$}
    \Up$\leftarrow$ \FindCompress{$Im[i-1,]$}}
    \lForEach{element $e$ of the line $i$}{\FindCompress{p}
  }
\rememberlines
\end{algorithm}

\begin{algorithm}
\resumenumbering
  \SetKwData{Left}{left}
  \SetKwData{Up}{up}
  \SetKwFunction{FindCompress}{FindCompress}
  \SetKwInOut{Input}{input}
  \SetKwInOut{Output}{output}

  \Indm
  \Input{A bitmap $Im$ of size $w\times l$}
  \Output{A partition of the bitmap}
  \Indp
  \BlankLine
  \For{$i\leftarrow 2$ \KwTo $l$}{
    \Left$\leftarrow$ \FindCompress{$Im[i,j-1]$}
    \Up$\leftarrow$ \FindCompress{$Im[i-1,]$}}
    \lForEach{element $e$ of the line $i$}{\FindCompress{p}
  }
\end{algorithm}

\end{document}

insira a descrição da imagem aqui

informação relacionada