.png)
특정 번호에서 코드를 시작하는 방법이 궁금합니다. 이는 알고리즘이 두 페이지에 걸쳐 분할될 때 필요합니다.
1번째 줄이 아닌 39번째 줄에서 시작하고 싶은 작은 예입니다. 할 수 있는 방법이 있나요?
\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}
친애하는!
답변1
패키지 에는 옵션이 algorithm2e
있지만 noresetcount
이는 모든 알고리즘에 연속적으로 번호를 매기는 효과가 있습니다.
\rememberlines
환경 종료 시 현재 행 번호를 저장하는 매크로 algorithm
와 \resumenumbering
해당 값을 사용하는 매크로를 정의할 수 있습니다 .
\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}