.png)
Ich frage mich, wie man einen Code bei einer bestimmten Zahl beginnen lässt; das ist notwendig, wenn der Algorithmus auf zwei Seiten aufgeteilt ist.
Ein kleines Beispiel: Ich möchte lieber in Zeile 39 statt in Zeile 1 beginnen. Gibt es eine Möglichkeit, das zu tun?
\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}
beste grüße!
Antwort1
Das algorithm2e
Paket verfügt zwar über eine noresetcount
Option, diese hat jedoch zur Folge, dass alle Algorithmen fortlaufend nummeriert werden.
Sie können ein Makro definieren \rememberlines
, das die Zeilennummer speichert, die am Ende einer algorithm
Umgebung aktuell war, und ein \resumenumbering
Makro, das diesen Wert verwendet.
\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}