.png)
Me pregunto cómo iniciar un código en un número específico; esto es necesario cuando el algoritmo se divide en dos páginas.
Un pequeño ejemplo que me gustaría comenzar en la línea 39 en lugar de la línea 1. ¿Hay alguna manera de hacerlo?
\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}
¡atentamente!
Respuesta1
El algorithm2e
paquete tiene una noresetcount
opción, pero esto tiene el efecto de numerar todos los algoritmos continuamente.
Puede definir una \rememberlines
macro que almacenará el número de línea actual al final de un algorithm
entorno y una \resumenumbering
macro que use ese 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}