0

I am using algpseudocode for writing an algorithm, and I would like to remove the "Algorithm X" from the title when adding a caption. How can I do this?

Example:

\documentclass{article}

\usepackage{algorithmicx, algpseudocode, algorithm}

\begin{document}

\begin{algorithm}
    \textbf{Input:} Placeholder input \\
    \textbf{Output:} Placeholder output
    \begin{algorithmic}[1]
        \Function{foo}{x} \\
        \Return $x+1$
        \EndFunction
    \end{algorithmic}
    \caption{Placeholder caption}
    \label{placeholder}
\end{algorithm}

\end{document}

Output:Output

How can I remove "Algorithm 1" from the title, and replace it with my own text, say "My text 1", where the counter also increases? I would still like to have a caption at the top, I just want to replace "Algorithm 1" with something else. I tried using figure instead of algorithm, but I would like to have the other formatting (horizontal lines) that the algorithm environment provides.

I have seen this, but that refers to algorithmic, not algorithmicx. Additionally, I would prefer a solution that can be applied to a specific algorithm instead of the whole document, since I have other algorithms where I want to keep the title intact.

Thank you.

2

Remove caption label and entry in \listofalgorithms

If you want to remove the caption label entirely, you could use the caption package and then \caption* (note, though, that this will remove the algorithm from the \listofalgorithms):

\documentclass{article}

\usepackage{caption}

\usepackage{algorithmicx, algpseudocode, algorithm}

\begin{document}

\begin{algorithm}
\textbf{Input:} Placeholder input \\
\textbf{Output:} Placeholder output
\begin{algorithmic}[1]
    \Function{foo}{x} \\
    \Return $x+1$
    \EndFunction
\end{algorithmic}
\caption*{Placeholder caption} % <-- CHANGED LINE
\label{placeholder}
\end{algorithm}

\end{document}

screenshot

Remove caption label (\listofalgorithms unchanged)

Using the caption package again, we can use \captionsetup{labelformat=empty} (see p. 6 of the caption documentation).

\documentclass{article}

\usepackage{algorithmicx, algpseudocode, algorithm}

\usepackage{caption}

\begin{document}

\begin{algorithm}
\captionsetup{labelformat=empty} % <-- CHANGED LINE
\textbf{Input:} Placeholder input \\
\textbf{Output:} Placeholder output
\begin{algorithmic}[1]
    \Function{foo}{x} \\
    \Return $x+1$
    \EndFunction
\end{algorithmic}
\caption{Placeholder caption}
\label{placeholder}
\end{algorithm}

\listofalgorithms

\end{document}

screenshot

Change caption label locally (\listofalgorithms unchanged)

If you want to locally change the caption label, you can use the \floatname command (see §4.4 of the algorithms documentation). For this you don't even need the caption package.

\documentclass{article}

\usepackage{algorithmicx, algpseudocode, algorithm}

\begin{document}

\begin{algorithm}
\floatname{algorithm}{Something} % <-- CHANGED LINE
\textbf{Input:} Placeholder input \\
\textbf{Output:} Placeholder output
\begin{algorithmic}[1]
    \Function{foo}{x} \\
    \Return $x+1$
    \EndFunction
\end{algorithmic}
\caption{Placeholder caption}
\label{placeholder}
\end{algorithm}

\end{document}

screenshot

3
  • Thank you (+1), this is partly helpful. Is there a way to replace the "Algorithm" title with something else, however? I will accept this if I don't get a better solution.
    – GoodDeeds
    Apr 28 '20 at 22:13
  • @GoodDeeds Working on it, the question got edited a few seconds before I posted my answer
    – steve
    Apr 28 '20 at 22:16
  • This is perfect, thank you! Appreciate your help in editing the question as well.
    – GoodDeeds
    Apr 29 '20 at 3:21

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.