2

I have defined a new block called Class in the algorithmicx package. I want to insert a break within this new block for a new page but I'm getting an error:

Package algorithmicx Error: Some blocks are not closed!!!.

Missing number, treated as zero. \End

This is my minimum working example for reproducing the errors:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
    \begin{algorithm}
        \algblock[Class]{Class}{End}
        \caption{Class: Part 1}\label{case_class_1}
        
        \begin{algorithmic}[1]
            \Class
            \Statex
            \Function{function 1}{ }
            \State do some stuff
            \EndFunction
            
            \algstore{bkbreak}

        \end{algorithmic}
    \end{algorithm}
    % BREAK
    \begin{algorithm}[h]
        \algblock[Class]{Class}{End}
        \caption{Class: Part 2}\label{case_class_2}
        
        \begin{algorithmic}[1]
            \algrestore{bkbreak}
            \Statex
            \Function{function 2}{ }
            \State do some stuff
            \EndFunction
            \End
        \end{algorithmic}
    \end{algorithm}
\end{document}

Errors:

line 32: Missing number, treated as zero. \End

line 33: Package algorithmicx Error: Some blocks are not closed!!!. \end{algorithmic}

2
  • 1
    Your code does not reproduce the error. The first error is missing \documentclass. Please provide the code of a small complete document, starting from \documentclass and ending with \end{document} that really compiles and illustrates your problem
    – gernot
    Mar 16, 2021 at 9:51
  • Apologies for the delay @gernot. Could you please have a look now? I've completed the minimum working example for reproducing the error. Mar 29, 2021 at 6:33

1 Answer 1

2

Define the new block in the preamble, instead twice in the algorithm environment. Besides, the [h] option for the second algorithm environment may be a problem if the second float overtakes the first one (which does not have the [h] option), as the \algrestore then might be executed before \algstore.

enter image description here

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\algblock[Class]{Class}{End}
\begin{document}
\begin{algorithm}
  \caption{Class: Part 1}\label{case_class_1}
  \begin{algorithmic}[1]
    \Class
    \Function{function 1}{ }
    \State do some stuff
    \EndFunction
    \algstore{bkbreak}
  \end{algorithmic}
\end{algorithm}
% BREAK
\begin{algorithm}
  \caption{Class: Part 2}\label{case_class_2}
  \begin{algorithmic}[h]
    \algrestore{bkbreak}
    \Function{function 2}{ }
    \State do some stuff
    \EndFunction
    \End
  \end{algorithmic}
\end{algorithm}
\end{document}
1
  • Can't believe this was so elementary. Thanks a lot. This works just fine. Apr 1, 2021 at 9:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .