I am trying to add some spacing above/below captions of algorithms using the algorithm2e package.
Consider the following example:
\documentclass[a4paper]{article}
\usepackage{blindtext}
\usepackage[linesnumbered,boxed]{algorithm2e}
\SetKwInput{KwInput}{Input}
\SetKwInput{KwOutput}{Output}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\KwInput{Parameters...}
\KwOutput{$\emptyset$}
\If{Condition}
{
Do something \;
}
\caption{Algoritm test...}
\end{algorithm}
\blindtext{}
\begin{figure}[!h]
\caption{Figure test...}
\end{figure}
\blindtext{}
\end{document}
You can see that the caption is squeezed in below the box containing the algorithm. There is no space separating the box from the caption and not enough space separating the caption from the following text. I would like to add the same amount of space above and below the caption, but I have not yet figured out how to do that: There seems to be a working solution for the algorithms package (see Algorithms package ignores caption package) , but I can't figure out how to make a \captionsetup
apply to an algorithm2e caption. Any ideas about this?
Best Answer
To use the command
\captionsetup
you must have loaded thecaption
package...Anyway, this can be done without it.
First of all, the spacing between the caption and the rest of the text is null because you are preventing the
algorithm
to float usingH
as a position specifier. Useh
instead, which means "place it here" but keeps thealgorithm
a floating object (the same ash
forfigure
s andtable
s).Then you can adjust the spacing between the body of the
algorithm
and its caption through the command\SetAlCapSkip
.In other words, substituting the line
with
and inserting
in the preamble (adjust
1em
to your needs) should be what you want.Complete MWE
Output