将算法分为两部分,不增加版本

将算法分为两部分,不增加版本

这是我的代码:

\documentclass{article}
\usepackage[paperheight=6\baselineskip]{geometry}% just for the example
\usepackage{algorithm}
\usepackage{algcompatible}

\begin{document}

\begin{algorithm}[H]
\caption{My algo}
\begin{algorithmic}[1]
\STATE instruction 1
\STATE instruction 2
\algstore{testcont} 
\end{algorithmic}
\end{algorithm}

\begin{algorithm}[H]
\caption{My algo - Part 2}
\begin{algorithmic}[1]
\algrestore{testcont} 
\STATE instruction 3
\STATE instruction 4
\end{algorithmic} 
\end{algorithm}
\end{document}

它显示:

Algorithm1 My algo and Algorithm2 My algo - Part 2

请问我怎样才能获得:

 Algorithm1 My algo and Algorithm1 My algo - Part 2

无增量?

谢谢

答案1

使用

\begin{algorithm}[H]
\caption{My algo}
\begin{algorithmic}[1]
\STATE instruction 1
\STATE instruction 2
\algstore{testcont} 
\end{algorithmic}
\addtocounter{algorithm}{-1}%% <===
\end{algorithm}

对于第一个算法

答案2

从包\ContinuedFloatcaption您还可以获得持续的行编号。

\documentclass{article}
\usepackage{algorithm}
\usepackage{algcompatible}
\usepackage{caption}

\begin{document}

\begin{algorithm}
\caption{My algo}
\begin{algorithmic}[1]
\STATE instruction 1
\STATE instruction 2
\algstore{testcont}
\end{algorithmic}
\end{algorithm}

\begin{algorithm}
\ContinuedFloat
\caption{My algo - Part 2}
\begin{algorithmic}[1]
\algrestore{testcont}
\STATE instruction 3
\STATE instruction 4
\end{algorithmic}
\end{algorithm}
\end{document}

在此处输入图片描述

相关内容