【Latex】IEEE的Latex模板中使用algorithm

​问题:在IEEEtran模板中,只允许使用figuretable浮动体环境,而不能使用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}

排版效果 

 

 

参考

  1. floats - How to use the algorithm2e package with IEEEtran class? - TeX - LaTeX Stack Exchange
  2. https://i.csdn.net/#/user-center/profile?spm=1001.2101.3001.5111
  3. IEEE的Latex模板中使用algorithm | 码农家园 

 

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值