【Latex学习】在IEEEtran模板中使用algorithm环境

【Latex学习】在IEEEtran模板中使用algorithm环境

参考链接:How to use the algorithm2e package with IEEEtran class?

根据IEEEtran模板的要求,IEEEtran只能使用figuretable环境,而不能使用algorithm环境。

IEEE publications use the figure environment to contain
algorithms that are not to be a part of the main text flow.
Peter Williams’ and Rogerio Brito’s algorithmic.sty package
[26] or Szász János’ algorithmicx.sty package [27] (the latter is
designed to be more customizable than the former) may be of
help in producing algorithm-like structures (although authors
are of course free to use whatever L A TEX commands they are
most comfortable with in this regard). However, do not use
the floating algorithm environment of algorithm.sty (also by
Williams and Brito) or algorithm2e.sty (by Christophe Fiorio)
as the only floating structures IEEE uses are figures and tables.
Furthermore, IEEEtran will not be in control of the (non-IEEE)
caption style produced by the algorithm.sty or algorithm2e.sty
float environments.

可以在\figure环境中调用\algorithm环境并使用[H]取消\algorithm的float属性,然后再使用\algorithmic\algorithm2e环境。

\usepackage{algorithmic}
\usepackage{algorithm}
\makeatletter
\newcommand{\removelatexerror}{\let\@latex@error\@gobble}
\makeatother

\begin{figure}[!t]
  \label{alg:LSB}
  \renewcommand{\algorithmicrequire}{\textbf{Input:}}
  \renewcommand{\algorithmicensure}{\textbf{Output:}}
  \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}$.
      \WHILE {there exists an element $a \in R\backslash S$ such that $\widetilde u(S \cup \left\{ a \right\}) > \left( {1 + \frac{\varepsilon }{{{n^2}}}} \right)\widetilde u(S)$}
      \STATE let $S \leftarrow S \cup \left\{ a \right\}$.
      \ENDWHILE
      \WHILE{there exists an element $a \in S$ such that $\widetilde u(S\backslash \left\{ a \right\}) > \left( {1 + \frac{\varepsilon }{{{n^2}}}} \right)\widetilde u(S)$}
      \STATE let $S \leftarrow S\backslash \left\{ a \right\}$.
      \ENDWHILE
      \STATE Return the maximum of $\widetilde u(S)$ and $\widetilde u(R\backslash S)$, where the local optimal set is $S$ or $R\backslash S$.
    \end{algorithmic}
  \end{algorithm}
\end{figure}

你可能感兴趣的:(latex)