8

Here is my minimal example:

\documentclass{article}

\usepackage{algorithm}
\usepackage{algorithmic}

\begin{document}

\begin{algorithm}
\caption{Test}
\begin{algorithmic}[1]
    \REQUIRE
    \REPEAT
    \STATE state
    \STATE state
    \STATE state
    \UNTIL condition
\end{algorithmic}
\end{algorithm}

\end{document}

I get this result:

enter image description here

But I would prefer this result:

enter image description here

How can I achive this?

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Andrew Swann Dec 6 '13 at 13:33
4

algorithmic creates all of the necessary pseudocode macros at the start of the algorithmic environment. As such, it's not as easy to merely patch \REPEAT and/or \UNTIL in the "usual" way.

The following MWE inserts the patch after the algorithmic environment starts. The patch uses a "no step" \item in the form of \ALC@it@nostep rather than the default \ALC@it:

enter image description here

\documentclass{article}

\usepackage{algorithm,algorithmic}% http://ctan.org/pkg/algorithms
\usepackage{xpatch,letltxmacro}% http://ctan.org/pkg/etoolbox
\makeatletter
\newcommand{\ALC@it@nostep}{\item[]}% No-step algorithmic item
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\LetLtxMacro\oldalgorithmic\algorithmic
\LetLtxMacro\endoldalgorithmic\endalgorithmic
\renewenvironment{algorithmic}[1][0]{%
  \oldalgorithmic[#1]%
  \xpatchcmd{\REPEAT}{\ALC@it}{\ALC@it@nostep}{}{}%
  \xpatchcmd{\UNTIL}{\ALC@it}{\ALC@it@nostep}{}{}%
}{\endoldalgorithmic}
\makeatother

\begin{document}

\begin{algorithm}
\caption{Test}
\begin{algorithmic}[1]
  \REQUIRE
  \REPEAT
  \STATE state
  \STATE state
  \STATE state
  \UNTIL condition
\end{algorithmic}
\end{algorithm}

\end{document}
|improve this answer|||||

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.