# algorithm2e - Caption without text

In the following code I would like to have a caption without text. In the following MWE there are unwanted colons because the caption is Algorithm 1: .

How can I fix that ?

\documentclass[12pt]{article}

\usepackage{algorithm2e}

\begin{document}

\begin{algorithm}
\caption{}

\While{\dots}{
\dots
}
\end{algorithm}

\end{document}


## 1 Answer

Set the relevant options:

\documentclass[12pt]{article}

\usepackage{algorithm2e}

\begin{document}

\begin{algorithm}
\SetAlgoCaptionSeparator{}% no separator, default colon
\SetAlCapNameSty{}% no caption text

\While{\dots}{
\dots
}

\caption{}

\end{algorithm}

\end{document}


If all your algorithms have no text in captions, you can place the two commands in the preamble:

\documentclass[12pt]{article}

\usepackage{algorithm2e}

\SetAlgoCaptionSeparator{}% no separator, default colon
\SetAlCapNameSty{}% no caption text

\begin{document}

\begin{algorithm}

\While{\dots}{
\dots
}

\caption{This text won't appear}

\end{algorithm}

\end{document}


If only some of the captions should be void, you can do

\documentclass[12pt]{article}

\usepackage{algorithm2e}

\newcommand{\voidcaption}[2][]{%
\SetAlgoCaptionSeparator{}% no separator, default colon
\SetAlCapNameSty{}% no caption text
\caption{}%
}

\begin{document}

\begin{algorithm}

\While{\dots}{
\dots
}

\voidcaption{This text won't appear}

\end{algorithm}

\end{document}


I'd not define \voidcaption without arguments, so that it would be easy to go back and typeset the given text instead.

• Thanks. Can I update your answer by adding a special macro \algojustcaption that does all the job ? Oct 1, 2019 at 11:13
• @projetmbc I added some suggestions. Oct 1, 2019 at 12:12
• I don't do the same thing. I prefer to build a macro using \begingroup and \endgroup, sucha as to localize the change of the settings, and calling \caption inside this group. Oct 1, 2019 at 12:31
• @projetmbc Why? The algorithm environment already provides for grouping. Oct 1, 2019 at 12:37
• You're right. I have done a weird test that makes me use an useful group. Your macro does not product any caption : there is a missing \caption{} in your void macro. Oct 1, 2019 at 15:14