I'm having issues trying to make the captions in Algorithn2e hang, as in the table caption pictured below. I plan on using them together with arsclassica
/classicthesis
, but it seems neither of these packages affect the issue.
I have tried using \usepackage[format=hang]{caption}
and \captionsetup{format=hang}
, but algorithm2e
seems not to be affected by them. The classicthesis
style file seems to be achieving this effect exactly this way. The algorithm2e
documentation doesn't mention hanging captions and I couldn't find anything (that I would decypher as caption code) in the style file either. Finally, google also didn't yield anything and I am finding myself a little bit out of depth with my latex skills here.
Here's a MWE:
\documentclass{scrreprt}
\usepackage[american]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[algoruled]{algorithm2e}
%\usepackage{classicthesis}
%\usepackage{arsclassica}
% these two lines don't make a difference
\usepackage[format=hang]{caption}
\captionsetup{format=hang}
\begin{document}
\begin{algorithm}[htb]
\While{true}
{
}
\caption{Morbi blandit vehicula leo a consectetur. Aliquam a lacus posuere, consectetur tortor at, mollis erat.}
\end{algorithm}
\end{document}
I have been able to format the rest of the algorithm2e
caption with some trial and error and hacking. I'm only interested in the hanging part of the problem here.
Best Answer
Here's one possible solution:
An image of the list of algorithms:
An image of the document showing the new environment in action:
The
algorithm
environment defined byalgorithm2e
is defined internally using thefloat
package, so it's behaviour is not exactly the same as the one for standard floats and the environment is not 100% compatible with some of the features of thecaption
package.One possible solution is then to un-define the
algorithm
environment defined by thealgorithm2e
package and define a newalgorithm
float with the help of thenewfloat
package. This new environment is fully compatible with thecaption
package, so one can use all the features offered by the package; in particular, settings like the hanging indentation will now apply directly (notice how nicely the new object inherits the settings fromclassicthesis
/arsclassica
).An
algrule
format was used to imitate the look and feel of theruled
style of the original environment. The\caption
command inside the newalgorithm
environment has to be used before the actual algorithm.The solution also takes care of producing a "List of Algorithms" following the settings of the other standard lists.
The procedure used is, in fact, recommended in the documentation of the
caption
package: