5

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}
3
  • I should note that I'm using the algpseudocode layout Dec 15, 2015 at 22:57
  • Welcome to TeX.SE. If you could provide a MWE, that will save the time of others. Dec 16, 2015 at 6:07
  • @SunilkumarKS Done. Dec 19, 2015 at 21:05

1 Answer 1

2

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

1
  • 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 Dec 21, 2015 at 20:10

You must log in to answer this question.

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