3

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}
6

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}

enter image description here

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 ? – projetmbc Oct 1 '19 at 11:13
  • @projetmbc I added some suggestions. – egreg Oct 1 '19 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. – projetmbc Oct 1 '19 at 12:31
  • 2
    @projetmbc Why? The algorithm environment already provides for grouping. – egreg Oct 1 '19 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. – projetmbc Oct 1 '19 at 15:14

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.