Algorithmus, wie die Zeilennummerierung bei einer gegebenen Nummer beginnt (mithilfe von Algorithmus2e)

Algorithmus, wie die Zeilennummerierung bei einer gegebenen Nummer beginnt (mithilfe von Algorithmus2e)

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 algorithm2ePaket verfügt zwar über eine noresetcountOption, 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 algorithmUmgebung aktuell war, und ein \resumenumberingMakro, 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}

Bildbeschreibung hier eingeben

verwandte Informationen