9

My problem is that I do not know how to disable the numbering for algorithms. I have created an algoritm and its number is "Algorithm 1", but I want to have "Algorithm".

\documentclass{article}

\usepackage[noend]{algorithmic} 
% Hide endif .etc

\usepackage{algorithm}

\algsetup{indent=2em} 
% Default 1 em

\renewcommand{\algorithmiccomment}[1]{\hspace{2em}// #1} 
% Change to C-style comments, though still ugly

\begin{document}
\begin{algorithm}
    \caption{MyAlgorithm} \label{alg:MyAlgorithm}
    \begin{algorithmic}[1]
    % Default no line numbering



    \end{algorithmic}
\end{algorithm}

\end{document}
2
  • 1
    how do you create the caption? Give a complete example – user2478 May 16 '11 at 7:28
  • @Herbert - added – colinfang May 16 '11 at 7:57
11

posting working examples would be a nice idea ... ;-) Now only page references make sense:

\documentclass{article}
\usepackage[noend]{algorithmic} 
\usepackage{algorithm,caption}
\algsetup{indent=2em} 
\renewcommand{\algorithmiccomment}[1]{\hspace{2em}// #1} 

\begin{document}
\begin{algorithm}
\caption*{MyAlgorithm} \label{alg:MyAlgorithm}
\begin{algorithmic}[1]
\item foo
\end{algorithmic}
\end{algorithm}

see algorithm on Page~\pageref{alg:MyAlgorithm}
\end{document}
4
  • A-HA, it works. thx – colinfang May 16 '11 at 9:31
  • Actually I didn't know we have to add caption package before using * – colinfang May 16 '11 at 9:32
  • What is your code doing? what is the part that disables numbering?? – Hao S Apr 18 '20 at 23:23
  • @colinfang how does this disable numbering? – Hao S Apr 21 '20 at 2:04
8

Setting the counter to nothing also works fine

\renewcommand{\thealgorithm}{}
1
  • 2
    Werner's answer gives some context about \thealgorithm macro in case anyone is looking for why this works – kon psych May 31 '18 at 17:48
6

The algorithm name and number are set as a combination. In general this is inside the "float macro" called \fnum@<float>. In the case of algorithm we see this definition for \fnum@algorithm:

> \fnum@algorithm=macro:
->\fname@algorithm {} \thealgorithm .

We can redefine this to only use \fname@algorithm (and therefore drop \thealgorithm - the algorithm numbering):

enter image description here

\documentclass{article}

\usepackage{algorithm,algpseudocode}

\makeatletter
\renewcommand{\fnum@algorithm}{\fname@algorithm}
\makeatother

\begin{document}

\begin{algorithm}
  \caption{MyAlgorithm}
  \begin{algorithmic}[1]
    \State An item
  \end{algorithmic}
\end{algorithm}

\end{document}

A similar interface/option is provided using the caption package:

\usepackage{caption}
\DeclareCaptionLabelFormat{algnonumber}{Algorithm}
\captionsetup[algorithm]{labelformat=algnonumber}

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.