3

I want to change the appearance of the caption for algorithms written by algorithm2e package using the caption package. In captionsetup one can easily customize the caption depending on the float type, whether a table, a figure, or a longtable even, but when I specified a captionsetup for algorrithms it didn't work, is there any way to change the Algorithm 1: to Algorithm 1.?

MWE Code:

\documentclass{scrartcl}
\usepackage{caption}
\captionsetup[longtable]{justification=justified} % works fine
\captionsetup[figure]{labelsep=period,format=plain, font={small}} % works fine
\captionsetup[algorithm]{labelsep=period,format=plain} % didn't work!
\usepackage{algorithm2e}
\begin{document}
\begin{algorithm}
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\end{document}

Output:
enter image description here

5

You have to use the command

\SetAlgoCaptionSeparator{.}

MWE

\documentclass{scrartcl}
\usepackage{caption}
\captionsetup[longtable]{justification=justified} % works fine
\captionsetup[figure]{labelsep=period,format=plain, font={small}} % works fine
%\captionsetup[algorithm]{labelsep=period,format=plain} % didn't work!
\usepackage{algorithm2e}
\SetAlgoCaptionSeparator{.}
\begin{document}
\begin{algorithm}
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\end{document} 

Output:

enter image description here

P.S. An extract from the caption package documentation:

Note: Some environments, e.g. the algorithm environment offered by the algorithm2e package, might react allergic to a change of the caption label format.

|improve this answer|||||
  • Section 9.2.2 setting style and layout of algorithm, caption and title (p 22) of the algorithm2e documentation. – Werner Jan 20 '14 at 18:18
  • when I changed the caption to ., I noticed that the counting numbers were not reset for each chapter of the book as was before. Is that what allergic means? – doctorate Jan 20 '14 at 18:26
  • @doctorate It might be one of the collateral effects... – karlkoeller Jan 20 '14 at 18:39

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.