算法分为两部分,需要连续 - 强制下面的文本

算法分为两部分,需要连续 - 强制下面的文本

由于算法太长,我将算法分成两页。我希望它们一个接一个地出现,但如果我像下面的代码那样做,第二部分之后的文本会挤在算法之间,所以在第一页。

  \documentclass{scrbook}
  \usepackage[utf8]{inputenc}
  \usepackage{algorithm}
  \usepackage{algpseudocode}

  \begin{document}

 \begin{algorithm} 
 \caption{My algorithm} 
 \begin{algorithmic} 
 \Require \(a, c, b ,d \) 
 \State some information and values.. 
 \State some information and values.. 
 \State some information and values.. 
 \State some information and values.. 
 \State some information and values.. 
 \State some information and values.. 
 \State some information and values.. 
 \For{\(j=e+1\) \textbf{TO} \(s-1\)} 
 \State do something 
 \If{eine Bedinung}
 \State doSomething
 \EndIf 
 \State Other..... 
 \algstore{alg:example}
 \end{algorithmic} 
 \end{algorithm} 


 \begin{algorithm}
 \begin{algorithmic}
 \algrestore{alg:example}
 \State lalalla
 \State lalalla
 \State lalalla
 \State lalalla
 \EndFor
 \end{algorithmic}
 \end{algorithm}

 Here is my text what floats between the algorithms but I want it to be below both of the second one, so that the algorithm parts are not interrupted...
 \end{document}

我尝试使用“h”或“t”强制浮动,但没有任何效果。我还尝试“拉长”第一个算法,因为文本会浮动到其页面,因为还剩下两行,但如果我这样做,完整的算法就会被推到另一页上……

答案1

您始终可以使用浮点说明符强制算法不浮动H

平均能量损失

  \documentclass{scrbook}
  \usepackage[utf8]{inputenc}
  \usepackage{algorithm}
  \usepackage{algpseudocode}
  \usepackage{lipsum} %just for the example

  \begin{document}

  \lipsum[1-3]

 \begin{algorithm}[H]
 \caption{My algorithm}
 \begin{algorithmic}
 \Require \(a, c, b ,d \)
 \State some information and values..
 \State some information and values..
 \State some information and values..
 \State some information and values..
 \State some information and values..
 \State some information and values..
 \State some information and values..
 \For{\(j=e+1\) \textbf{TO} \(s-1\)}
 \State do something
 \If{eine Bedinung}
 \State doSomething
 \EndIf
 \State Other.....
 \algstore{alg:example}
 \end{algorithmic}
 \end{algorithm}


 \begin{algorithm}[H]
 \begin{algorithmic}
 \algrestore{alg:example}
 \State lalalla
 \State lalalla
 \State lalalla
 \State lalalla
 \EndFor
 \end{algorithmic}
 \end{algorithm}

 Here is my text what floats between the algorithms but I want it to be below both of the second one, so that the algorithm parts are not interrupted...
 \end{document} 

输出

在此处输入图片描述

答案2

正确的方法是使用

\algstore

\algstore{bkbreak}
\algrestore{bkbreak}

http://tug.ctan.org/macros/latex/contrib/algorithmicx/algorithmicx.pdf

而有时候当你破坏算法时,一些文本会填充在算法的两个部分之间,这很烦人。
我终于发现,为了避免文本进入,你需要让你的第一个算法页面几乎满了

相关内容