Algorithm2e: Caption does not match style of Figure and Table captions

Algorithm2e: Caption does not match style of Figure and Table captions

Post by Oz Sh » Tue, 14 Aug 2007 21:19:24

A copyeditor has pointed out to me that the ":" in the caption:
Algorithm 2: is NOT bold. This style is inconsistent with Figure 2: or
Table 2: where the ":" are in boldface.

I would be most grateful if somebody could tell me how to fix this
inconsistency. Thanks for your help, Oz.

Algorithm2e: Caption does not match style of Figure and Table captions

Post by Werner Gru » Wed, 15 Aug 2007 05:20:07

Of course there are 2 solutions to this 'problem'. You could (1)
change the figure and table environment captions to set the ':' in
normal typeface (rather than bold), or (2) change the typeface of the
':' in the algorithm environment to be typeset in bold (rather than

(1) This may be done by using the caption package, available from CTAN
Formatting an environment caption is typically performed via the
\captionsetup[<float type>]{<options>}
where you specify the <float type> (for example, figure or table) and
the available <options>. More specifically, you would have to add
something like
\DeclareCaptionLabelSeparator{normal-colon}{\normalfont : } % In
your main *** document preamble

(2) This seems to be a bit harder, because it has its own caption
typesetting macros, and doesn't allow for separate typesetting change
of the algorithm name & number combination (Algorithm ??) and the
caption/label separator (':' in this case). I suggest edding the
actual algorithm2e style file to obtain this. Additionally, the
algorithm2e doesn't seem to be well maintained, according to my
experience, producing 'Overfull \hbox' warnings even when typesetting
an empty algorithm! It would be great if it compatibility with the
caption package could be introduced.

Hence...the short solution: I would suggest using (1) to resolve your



Algorithm2e: Caption does not match style of Figure and Table captions

Post by Oz Sh » Wed, 15 Aug 2007 08:33:41

Thanks for your help. Indeed, modifying algorithm2e.sty was easy. The
relevant line is:
\AlCapFnt{}#2} %
%where I added the \textbf around the ":" Oz.

Algorithm2e: Caption does not match style of Figure and Table captions

Post by Axel Somme » Wed, 15 Aug 2007 17:02:11

i Werner,

Werner Grundlingh < XXXX@XXXXX.COM > wrote:

I tend to agree, but I will definitly never do this, unless someone will
pay me for such pains.

Here is why: The author of the algorithm2e package has decided to get rid
of the float package and to include all its code for himself. Afterwards he
changed all the code which initially came from the float package in a way
which makes it nearly impossible for me to find proper `hooks' for the
caption package.

Please take a look at the float package adaption code within the caption
package, it's some kind of horror, because there isn't even a good way to
detect which float style will be used by which float. Furthermore there is
no clean way to detect if \restylefloat or \restylefloat* was used, which
is a essention information for typesetting captions within such
environment. The algorithm for this within the float package itself isn't
reliable as well, because it fails when \@caption will be redefined. And so

Now try to imagine what I have to do when I try to make the caption package
compatible to the algorithm2e package... :-(

My personal suggestion when you want to customize captions coming from the
algorithm2e package:

\renewenvironment{algocf}[1][h]{}{}% pass over the floating stuff

This makes an "algorithmic" environment which does not use a floating
environment. Afterwards you can define your own new "proper" floating
environment with \newfloat from the float package, and use the combination
of this floating environment and "algorithmic" in it's body, just like you
should do when you use the algorithm/algorithmic package tandem.

You can even use the algorithm package for this purpose, for example:


%--- this could go into myalgorithm2e.sty ---
% save the "algorithm" from the algorithm2e package
% define the algorithmic environment, based on the saved environment
\renewenvironment{algocf}[1][h]{}{}% pass over the floating stuff
% load the algorithm package to re-define the floating environment
% "algorithm" and \listofalgorithms
%--- end of myalgorithm2e.sty ---


% algorithm without float:
a line\;
a line\;
another line\;
another line\;

% algorithm with float:
\caption{A algorithm}
a line\;
a line\;
another line\;
another line\;


A totally different idea would be using the algorithmicx package instead of
the algorithm2e package.

(I will put this into the documentation of the upcoming caption package

Axel (Author of the caption package)