我尝试了在这里找到的几种方法,包括这, 和这,还有更多但我记不清了。
我遇到的问题是,我希望“第五条指令”从 5 开始,我知道“第三条指令”碰巧有正确的数字,但我的所有尝试似乎都不起作用。我很高兴缩进的部分自动重新编号,但即使它是一个从上到下编号(1-13)但缩进的,我也会很高兴——我似乎也无法做到这一点。
非常感谢您的帮助!
\usepackage{algorithm,algpseudocode}
\usepackage{algorithm2e}
\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\State First Instruction
\State Second Instruction
\begin{algorithmic}[1]
\State Instruction 2.1
\State Instruction 2.2
\end{algorithmic}\\
Third Instruction\\
Fourth Instruction
\begin{algorithmic}[1]
\State Instruction 4.1
\State Instruction 4.2
\State Instruction 4.3
\end{algorithmic}\\
Fifth Instruction
\begin{algorithmic}[1]
\State Instruction 5.1
\State Instruction 5.2
\end{algorithmic}\\
Instruction 6
\end{algorithmic}
\end{algorithm}
答案1
连续编号的一个简单方法是使用 的额外缩进\hspace
。为了与 的默认缩进保持一致,algorithmic
您可以使用\algorithmicindent
作为额外缩进的值(这是1.5em
默认值)。
MWE(请注意,我已删除它,algorithm2e
因为它导致了错误):
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\State First Instruction
\State Second Instruction
\State\hspace{\algorithmicindent} Instruction 2.1
\State\hspace{\algorithmicindent} Instruction 2.2
\State Third Instruction
\State Fourth Instruction
\State\hspace{\algorithmicindent} Instruction 4.1
\State\hspace{\algorithmicindent} Instruction 4.2
\State\hspace{\algorithmicindent} Instruction 4.3
\State Fifth Instruction
\State\hspace{\algorithmicindent} Instruction 5.1
\State\hspace{\algorithmicindent} Instruction 5.2
\State Instruction 6
\end{algorithmic}
\end{algorithm}
\end{document}
结果: