[Tex/LaTex] Algorithm split in two parts, need to be consecutive – forcing the text bellow

algorithms

I am splitting my algorithm over two pages, since it is to long. And I would like them to appear one after the other, but If I do it like in the code below, the text coming after the second part pushes between the algorithms, so on page 1..

  \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}

I tried to force the floats with "h" or "t" but nothing is working. I also tried to "elongate" first algorithm, because the text floats up to its page since there are two lines left, but if i do that the complete algorithm is pushed onto another page…

Best Answer

You can always force the algorithms not to float using the the floating specifier H.

MWE

  \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} 

Output

enter image description here