Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My question is about algorithmic package. I have an algorithm which I called A1.

\begin{algorithm}
\caption{\bf A1:}
\label{algorithm-A1}
...

I have something like this:

Algorithm 1 A1

How can I make that I will get

Algorithm A1

And another question how I can labelling so that when I use \ref{algorithm-A1}, then link will appear as A1 in a text.

share|improve this question
1  
While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. While solving problems is fun, setting them up is not. Then those trying to help can simply cut and paste your MWE and get started on solving problem. –  Peter Grill Nov 14 '12 at 4:04
    
Using \renewcommand{\thealgorithm}{A\arabic{algorithm}} should modify the \label-\ref you're using. However, the bigger question is the use of {\bf A1}. What does this represent? –  Werner Nov 14 '12 at 4:11
add comment

1 Answer

up vote 3 down vote accepted

The following works for me, note in particular the line

\renewcommand{\thealgorithm}{A\arabic{algorithm}}

which @Werner mentioned in his comment. Note also that this code is an example of a MWE

enter image description here

\documentclass{article}

\usepackage{algorithm}
\usepackage{algpseudocode}
\renewcommand{\thealgorithm}{A\arabic{algorithm}}

\begin{document}

\begin{algorithm}
    \caption{Euclid’s algorithm}
    \label{alg:euclid}
    \begin{algorithmic}[1]
        \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
        \State $r\gets a\bmod b$
        \While{$r\not=0$}\Comment{We have the answer if r is 0}
        \State $a\gets b$
        \State $b\gets r$
        \State $r\gets a\bmod b$
        \EndWhile\label{euclidendwhile}
        \State \textbf{return} $b$\Comment{The gcd is b}
        \EndProcedure
    \end{algorithmic}
\end{algorithm}

Test reference: \ref{alg:euclid}

\end{document}
share|improve this answer
    
could please comments why does it work. I want to understand what should I change so that I will have various numeration like "Algorihtm A0", "Algorihtm A0M". thank you! –  msh Nov 15 '12 at 7:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.