I am using algorithm2e to explain my algorithm and surrounding it within float environment for IEEETran class as suggested in How to use the algorithm2e package with IEEEtran class?
Below is a sample code:
\documentclass[conference]{IEEEtran}
\usepackage[font=scriptsize]{caption}
\usepackage{subcaption}
\usepackage[plain, vlined, linesnumbered, noresetcount]{algorithm2e}
\makeatletter
\newcommand{\removelatexerror}{\let\@latex@error\@gobble}
\makeatother
\begin{document}
\begin{figure}
\removelatexerror
\begin{algorithm}[H]
\textbf{struct} Node \{ \\
\Indp
\textbf{Int} key;\\
Node* child[2];\\
\Indm
\}; \\
\end{algorithm}
\hrule
\captionsetup{justification=centering}
\caption{Node structure}
\label{alg:NodeStructure}
\end{figure}
Figure \ref{alg:NodeStructure} represents a node in our tree
\end{document}
After I compile this code, I see a significant gap between the text and my algorithm. Is there any way to reduce this gap.
Best Answer
This is not particular to
algorithm2e
, but more so to do with the natural gaps between floats and the surrounding text as laid out by the class. Here is a quick view on the lengths involved in the separation:The default lengths for
IEEEtran
are\floatsep
:0.85\baselineskip plus 0.2\baselineskip minus 0.2\baselineskip
\textfloatsep
:1.55\baselineskip plus 0.2\baselineskip minus 0.4\baselineskip
\intextsep
:0.85\baselineskip plus 0.2\baselineskip minus 0.2\baselineskip
These are all fairly large, but allow for some manoeuvring within a two-column layout (due to the
plus
andminus
). Here's the view with\textfloatsep
set to0pt
: