1

To spread a pseudo code algorithm over multiple pages, I tried using algstore and algrestore as e.g. described here: Pseudo code to be spread over multiple pages? This solution works fine with the algpseudocode package, but the algpseudocodex package leads to many errors in the second part of the algorithm. Here is an example:

\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{algpseudocodex}
\usepackage{algorithm}

\begin{document}

\begin{algorithm}
\caption{Part 1}
\begin{algorithmic}[1]
\Procedure {BellmanKalaba}{$G$, $u$, $l$, $p$}
\ForAll {$v \in V(G)$}
\State $l(v) \leftarrow \infty$
\EndFor
\State $l(u) \leftarrow 0$
\Repeat
\For {$i \leftarrow 1, n$}
\State $min \leftarrow l(v_i)$
\For {$j \leftarrow 1, n$}
\If {$min > e(v_i, v_j) + l(v_j)$}
\State $min \leftarrow e(v_i, v_j) + l(v_j)$
\State \Comment For some reason we need to break here!
\algstore{bkbreak}
\end{algorithmic}
\end{algorithm}

\addtocounter{algorithm}{-1}
\begin{algorithm}[h]
\caption{Part 2}
\begin{algorithmic}[1]
\algrestore{bkbreak}
\State $p(i) \leftarrow v_j$
\EndIf
\EndFor
\State $l’(i) \leftarrow min$
\EndFor
\State $changed \leftarrow l \not= l’$
\State $l \leftarrow l’$
\Until{$\neg changed$}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}

This code works fine with the algpseudocode package, but the second part of the algorithm is totally broken with the algpseudocodex package. Why is that? I thought that algpseudocodex is an extension that should include all algpseudocode functionality. Do you know any workaround to this problem?

1 Answer 1

1

You can break your algorithm if you switch off the indent lines. They are drawn with tikz and a tikz picture can't be (easily) broken across multiple pages.

\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage[indLines=false]{algpseudocodex}
\usepackage{algorithm}

\begin{document}

\begin{algorithm}
\caption{Part 1}
\begin{algorithmic}[1]
\Procedure {BellmanKalaba}{$G$, $u$, $l$, $p$}
\ForAll {$v \in V(G)$}
\State $l(v) \leftarrow \infty$
\EndFor
\State $l(u) \leftarrow 0$
\Repeat
\For {$i \leftarrow 1, n$}
\State $min \leftarrow l(v_i)$
\For {$j \leftarrow 1, n$}
\If {$min > e(v_i, v_j) + l(v_j)$}
\State $min \leftarrow e(v_i, v_j) + l(v_j)$
\State \Comment For some reason we need to break here!
\algstore{bkbreak}
\end{algorithmic}
\end{algorithm}

\addtocounter{algorithm}{-1}
\begin{algorithm}[h]
\caption{Part 2}
\begin{algorithmic}[1]
\algrestore{bkbreak}
\State $p(i) \leftarrow v_j$
\EndIf
\EndFor
\State $l’(i) \leftarrow min$
\EndFor
\State $changed \leftarrow l \not= l’$
\State $l \leftarrow l’$
\Until{$\neg changed$}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.