2

I am trying to have pseudocode similar to that in this article. I am currently using the algorithmicx package. My problem is that I would like to have the caption look like below:

enter image description here

So in caps and complete with arguments. I can't seem to figure out how to do this. Below is an example. Basically I would want the "Euclid(a,b)" to be in the caption, instead of the body after procedure.

\documentclass[11pt]{article} 

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

\floatname{algorithm}{Procedure}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\renewcommand\thealgorithm{}

\begin{document}

\begin{algorithm}
\caption{Euclid’s algorithm}
\begin{algorithmic}[1]
\Require Integers $a$ and $b$
\Ensure The g.c.d of $a$ and $b$
\Procedure{Euclid}{$a,b$}
\State $r\gets a\bmod b$
\While{$r\not=0$}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile
\State \textbf{return} $b$
\EndProcedure
\end{algorithmic}
\end{algorithm}

\end{document}
  • Welcome to TeX.SE. It would be helpful if you composed a fully compilable minimal working example (MWE) including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – samcarter is at topanswers.xyz Feb 17 '18 at 19:50
2

The trick is to use \textproc, as below:

\documentclass[11pt]{article} 

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

\floatname{algorithm}{Procedure}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\renewcommand\thealgorithm{}

\begin{document}

\begin{algorithm}
\caption{\textproc{Euclid}$(a,b)$}
\begin{algorithmic}[1]
\Require Integers $a$ and $b$
\Ensure The g.c.d of $a$ and $b$
\State $r\gets a\bmod b$
\While{$r\not=0$}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile
\State \textbf{return} $b$
\end{algorithmic}
\end{algorithm}

\end{document}

This results in enter image description here

Incidentally, this is also useful when you wish to refer to an algorithm in the text.

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.