4

I'm trying to define some sort of algorithmicx command to give me this:

\Statex \textbf{Local State:}
\Statex \hspace{\algorithmicindent} $v \gets []$
\Statex \hspace{\algorithmicindent} $h \gets \bot$

goal

I've tried

\algloopdefx{LocalState}{\textbf{LocalState:}}

which results in a line number in front of Local State:, and I've tried

\algloopdefx{LocalState}{\Statex\textbf{LocalState:}}

but that results in blank line with a line number (probably because the \algloopdefx macro puts a \State at the beginning of the <start> line.

Is there any way to produce the sample above without resorting putting an hspace at the beginning of every line or similar dirty hacks?

EDIT: Adding MWE

\documentclass{article}

\usepackage{algorithm, algorithmicx, algpseudocode}

\begin{document}

\begin{algorithm}
\caption{Algorithm}
\begin{algorithmic}[1]

\Statex \textbf{Local State:}
  \Statex \hspace{\algorithmicindent} Foo
  \Statex \hspace{\algorithmicindent} Bar
\Statex

\Procedure{Foobar}{}
  \State Numbering should start at this procedure
\EndProcedure

\end{algorithmic}
\end{algorithm}

\end{document}
  • I should note that I'm using the algpseudocode layout – Ellis Michael Dec 15 '15 at 22:57
  • Welcome to TeX.SE. If you could provide a MWE, that will save the time of others. – Sunilkumar KS Dec 16 '15 at 6:07
  • @SunilkumarKS Done. – Ellis Michael Dec 19 '15 at 21:05
1

Just define new macro, say \StateX as follows, that will solve the problem.

\documentclass{article}

\usepackage{algorithm, algorithmicx, algpseudocode}

\newcommand\StateX{\Statex\hspace{\algorithmicindent}}

\begin{document}

\begin{algorithm}
\caption{Algorithm}
\begin{algorithmic}[1]

\Statex \textbf{Local State:}
  \StateX  Foo
  \StateX  Bar

\Procedure{Foobar}{}
  \State Numbering should start at this procedure
\EndProcedure

\end{algorithmic}
\end{algorithm}

\end{document}

enter image description here

  • And then StateX is redefined permanently. Looks like I'll probably have to make some macros like StartLocalState, EndLocalState that keep the old StateX in a temp – Ellis Michael Dec 21 '15 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.