16

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 Commented May 16, 2011 at 7:28
  • @Herbert - added Commented May 16, 2011 at 7:57

3 Answers 3

15

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 Commented May 16, 2011 at 9:31
  • Actually I didn't know we have to add caption package before using * Commented May 16, 2011 at 9:32
  • 1
    What is your code doing? what is the part that disables numbering?? Commented Apr 18, 2020 at 23:23
  • 1
    @colinfang how does this disable numbering? Commented Apr 21, 2020 at 2:04
12

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 Commented May 31, 2018 at 17:48
10

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}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.