我正在使用 algorithm2e 来解释我的算法,并将其围绕在 IEEETran 类的浮点环境中,正如如何将 algorithm2e 包与 IEEEtran 类一起使用?
以下是示例代码:
\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}
答案1
这并不特别algorithm2e
,但更重要的是与浮动和周围文本之间的自然间隙有关,正如班级。以下是分离所涉及的长度的快速视图:
默认长度IEEEtran
为
\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
这些都相当大,但允许在两列布局中进行一些操作(由于 和plus
) 。以下是设置为 的minus
视图:\textfloatsep
0pt
\documentclass[conference]{IEEEtran}
\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
\caption{Node structure}
\end{figure}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In finibus est in pulvinar semper.
Nullam a mauris nibh. Aliquam egestas quam at vulputate condimentum. Suspendisse quis velit eros.
\newpage
\setlength{\textfloatsep}{0pt}
\begin{figure}
\removelatexerror
\begin{algorithm}[H]
\textbf{struct} Node \{ \\
\Indp
\textbf{Int} key;\\
Node* child[2];\\
\Indm
\};
\end{algorithm}
\hrule
\caption{Node structure}
\end{figure}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In finibus est in pulvinar semper.
Nullam a mauris nibh. Aliquam egestas quam at vulputate condimentum. Suspendisse quis velit eros.
\end{document}