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
normal).

(1) This may be done by using the caption package, available from CTAN
at
http://www.yqcomputer.com/
Formatting an environment caption is typically performed via the
command
\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
\captionsetup[figure]{labelfont=bf,labelsep=normal-colon}
\captionsetup[table]{labelfont=bf,labelsep=normal-colon}

(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
'problem'.

Werner

 
 
 

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:
\newcommand{\algocf@captiontext}[2]{#1\algocf@typo\textbf{:}
\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
on...

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:

\newenvironment{algorithmic}{%
\renewenvironment{algocf}[1][h]{}{}% pass over the floating stuff
\algorithm
}{%
\endalgorithm
}

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:

\documentclass{article}

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

\begin{document}

% algorithm without float:
\begin{algorithmic}
\SetVline
\eIf{cond1}{
a line\;
a line\;
}{
another line\;
another line\;
}
\end{algorithmic}

% algorithm with float:
\begin{algorithm}[H]
\caption{A algorithm}
\begin{algorithmic}
\SetVline
\eIf{cond1}{
a line\;
a line\;
}{
another line\;
another line\;
}
\end{algorithmic}
\end{algorithm}

\end{document}

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
v3.1)

Axel (Author of the caption package)