hithesis icon indicating copy to clipboard operation
hithesis copied to clipboard

算法环境断页换行

Open GuoHuanyu opened this issue 1 year ago • 1 comments

提供一个解决思路

 \begin{algorithm}[!ht] 
      \AlgoBiCaption{XXX算法}{XXXX Algorithm}
      \label{alg2-3}   
      \KwIn{}
      \KwOut{}
     xxxx\\
          xxxxx \\  
      \SetKwBlock{Begin}{while xxx do}{}
      \SetAlgoLined
      \SetKwProg{If}{if}{}{}
      \SetKwProg{For}{for}{}{}
        \Begin{ 
          \SetAlgoVlined \If{XXXXX \rm\textbf{then}}{
            \SetAlgoVlined  \If{$XX$ \rm\textbf{then}}{
            XX$XXX$\\
            } 
            \SetAlgoVlined \For{$XXX$ \rm\textbf{do}}{
              XX\\
              \SetAlgoVlined \If{$XX \geq 0$ \rm\textbf{then}}{
                \SetAlgoVlined \If{XXXXX\rm\textbf{then}}{
                  XXXXX\\
                }
              }
            }
            \SetAlgoVlined\If{xx \rm\textbf{then}}{
              xx\\
              \SetAlgoVlined\If{xxx \rm\textbf{then}}{
                xxx\\
              }
              \SetAlgoVlined \If{xx\rm\textbf{then}}{
                \SetAlgoVlined \If{xxx\rm\textbf{then}}{
      
               xx\\
              }
              }
            }
            
         xx\\
            xx\\ 
            \SetAlgoVlined \If{xx \rm\textbf{then}}{
             xx\\
            }   
      
            }
        }
      \end{algorithm}
      \begin{algorithm} [t] 
      \setcounter{AlgoLine}{22}  
      \SetKwBlock{Begin}{}{end}
      \nonl \Begin{
        xxx\\
     xx\\  
        }
      \end{algorithm}

为了使用 \nonl命令屏蔽掉 \SetKwBlock{Begin}{}{end}这行的行号,在\begin{document}之前加入以下

\makeatletter
\newcommand{\nosemic}{\renewcommand{\@endalgocfline}{\relax}}% Drop semi-colon ;
\newcommand{\dosemic}{\renewcommand{\@endalgocfline}{\algocf@endline}}% Reinstate semi-colon ;
\newcommand{\pushline}{\Indp}% Indent
\newcommand{\popline}{\Indm\dosemic}% Undent
\let\oldnl\nl% Store \nl in \oldnl
\newcommand{\nonl}{\renewcommand{\nl}{\let\nl\oldnl}}% Remove line number for one line
\makeatother

GuoHuanyu avatar Jun 30 '24 16:06 GuoHuanyu