问题:在IEEEtran模板中,只允许使用figure
和table浮动体
环境,而不能使用algorithm浮动体
环境。
但直接使用\figure浮动体环境,算法标题为图片标题样式,且没有算法的上中下三条线,很不美观。
解决办法是:
在\figure
环境中嵌套\algorithm
环境并使用[H]
取消\algorithm
的float属性,然后再使用\algorithmic
或\algorithm2e
环境。
下面提供几个模板
首先,导言区添加
%for algorithmic.sty
\usepackage{algorithm}
\usepackage{algorithmic}
% or for algorithmicx.sty
%\usepackage{algorithmicx}
%\usepackage{algpseudocode}
%\floatname{algorithm}{Protocol} %Customize to your needs
\renewcommand{\algorithmicrequire}{\textbf{Input:}} % Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm
\makeatletter
\newcommand{\removelatexerror}{\let\@latex@error\@gobble}
\makeatother
1. 对于algorithmic.sty 排版样式
\begin{figure}[!t]
\label{alg:LSB}
\removelatexerror
\begin{algorithm}[H]
\caption{Local Search Based Algorithm}
\begin{algorithmic}[1]
\REQUIRE Candidate set $\mathbb{S}$, Initial set $\mathbb{X} = \varnothing$ %%input
\ENSURE Optimum set $\mathbb{X}$ %%output
\STATE {set $r(t)=x(t)$}
\end{algorithmic}
\end{algorithm}
\end{figure}
排版效果
2. 对于algorithmicx.sty 排版样式
\begin{figure}[!t]
\label{alg:LSB}
\removelatexerror
\begin{algorithm}[H]
\caption{Local Search Based Algorithm}
\begin{algorithmic}[1]
\Require Candidate set $\mathbb{S}$, Initial set $\mathbb{X} = \varnothing$
\Ensure Optimum set $\mathbb{X}$
\State Let $\mathbb{X} \leftarrow r$, if $\widetilde u({v})$ is the maximum over all singletons $r \in \mathbb{S}$.
\end{algorithmic}
\end{algorithm}
\end{figure}
排版效果
参考
- floats - How to use the algorithm2e package with IEEEtran class? - TeX - LaTeX Stack Exchange
- https://i.csdn.net/#/user-center/profile?spm=1001.2101.3001.5111
- IEEE的Latex模板中使用algorithm | 码农家园