2

If you want to write an algorithm, you have to write three commands to initialize a writing environment.

\usepackage{algorithm}
\usepackage[noend]{algpseudocode}

\begin{algorithm} % no.1
\begin{algorithmic} % no.2
\Procedure{Sum}{100} % no.3
\State abcd
\EndProcedure
\end{algorithmic}
\end{algorithm}

And write three lines to end it. So is there any way to wrap it up, using one command to simplify it?

3

You can define a myalgorithm environment (you can call it anything you want) that does this. If you add

\newenvironment{myalgorithm}[2]
  {\begin{algorithm}\begin{algorithmic}\Procedure{#1}{#2}}
  {\EndProcedure\end{algorithmic}\end{algorithm}}

you can use this in your document as

\begin{myalgorithm}{Sum}{100}
  \State abcd
\end{myalgorithm}

The two arguments are those that are given to the \Procedure command. Note that this will not allow you to add a caption or label to the algorithm floating environment.

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.