How can I split two steps in one algorithm box for LaTeX?

How can I split two steps in one algorithm box for LaTeX like below image?

Thank you very much.

• Are you tied to this output, or are you open to alternatives that might be more visually appealing? What are the restrictions in terms of packages? – Werner Sep 7 '16 at 6:23
• I'm trying to reduce context due to letter's volume by tying two steps in one algorithm. I have no restrictions in terms of packages. I only want to solve this problem. Is there any solution? – Dongkyu Sim Sep 7 '16 at 7:04

Perhaps you can use \Statex from algpseudocode to "comment" a step or break:

\documentclass{article}

\usepackage{algorithm,algpseudocode}
\algnewcommand{\And}{\textbf{and}}

\begin{document}

\begin{algorithm}
\caption{A two-step algorithm}
\begin{algorithmic}[1]
\Statex \textit{First step}
\While{$X\ \And\ Y$}
\State Statement~1
\If{$Z$}
\State Statement~2
\EndIf
\EndWhile
\Statex \textit{Second step}
\While{$Y\ \And\ X$}
\State Statement~3
\If{$Z$}
\State Statement~4
\EndIf
\EndWhile
\end{algorithmic}
\end{algorithm}

\end{document}

• Here is a very simple adaptation that adds hrules above and below text: \newcommand{\algstep}[1]{\item[]\medskip\hrule\kern 2pt\hbox to \textwidth{\hspace{\labelsep}\textbf{#1}\hfill}\hrule} – Francis Sep 7 '16 at 7:46