3

If I typeset a simple algorithm using the algorithmicx package, say

\documentclass{article}
\usepackage{algpseudocode}
\usepackage{algorithm}

\begin{document}

\begin{algorithm}[H]
  \caption{Bisection}
  \label{alg:1}
\begin{algorithmic}
  \Repeat
    \State $t\gets \frac{a+b}{2}$
    \State and so on...
  \Until{$f(t)>\epsilon$}
\end{algorithmic}
\end{algorithm}

\end{document}

the result looks similar to:

compiled latex

How do I add a colon behind the number of the algorithm, i.e. i would like to get

Algorithm A.1: Bisection

My first idea was to redefine thealgorithm as

%\renewcommand{\thealgorithm}{\thechapter.\arabic{algorithm}:}

However, in this case every time I reference an algorithm I also gain the colon. Bad idea. Of course I could redefine the command before and after the algorithm environment or create my own environment that encapsulates algorithm and makes the corresponding definitions. But is there a better way?

karlkoeller
  • 124,410
Thilo
  • 598

1 Answers1

7

Load the caption package and define

\captionsetup[algorithm]{labelsep=colon}

MWE:

\documentclass{article}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{caption}
\captionsetup[algorithm]{labelsep=colon}

\begin{document}

\begin{algorithm}[H]
  \caption{Bisection}
  \label{alg:1}
\begin{algorithmic}
  \Repeat
    \State $t\gets \frac{a+b}{2}$
    \State and so on...
  \Until{$f(t)>\epsilon$}
\end{algorithmic}
\end{algorithm}

\end{document} 

Output:

enter image description here

karlkoeller
  • 124,410