ieee会议latex模板,伪代码写法


%\usepackage{algorithmic}
% algorithmic.sty was written by Peter Williams and Rogerio Brito.
% This package provides an algorithmic environment fo describing algorithms.
% You can use the algorithmic environment in-text or within a figure
% environment to provide for a floating algorithm. Do NOT use the algorithm
% floating environment provided by algorithm.sty (by the same authors) or
% algorithm2e.sty (by Christophe Fiorio) as the IEEE does not use dedicated
% algorithm float types and packages that provide these will not provide
% correct IEEE style captions. The latest version and documentation of
% algorithmic.sty can be obtained at:
% http://www.ctan.org/pkg/algorithms
% Also of interest may be the (relatively newer and more customizable)
% algorithmicx.sty package by Szasz Janos:
% http://www.ctan.org/pkg/algorithmicx
我本来想用algorithmic的,但是那个实在是不好看,下面贴一个简单版本的algorithmic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}

% 中略

\begin{figure}[!t]
  \begin{algorithm}[H]
    \caption{Caption}
    \label{alg1}
    \begin{algorithmic}
      \Require args $x_i$
      \Ensure total $s$
      \State $s \leftarrow 0$
      \For{$i=1,\cdots,n$}
        \State $s \leftarrow s + x_i$
      \EndFor
      \State \Return $s$
    \end{algorithmic}
  \end{algorithm}
\end{figure}

下面是我用figure和algorithm2e写的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
\usepackage[ruled,linesnumbered]{algorithm2e}

\usepackage{algpseudocode}
\makeatletter
\newcommand{\removelatexerror}{\let\@latex@error\@gobble}
\makeatother
%中略
\begin{figure}[!t]
        \removelatexerror
        \begin{algorithm}[H]
            \caption{hehh}
            \LinesNumbered
            \KwIn{FFT Bins $B_{1}, B_{2}, B_{3}, ..., B_{n}$}
            \KwOut{Event start point $S$, end point $E$}
            \For{i=1:n}{   
                \eIf{max($B_{i}$) : max($B_{(i+4)}$)$>$-80}{
                    $S$=i; \tcp*{Start Point}
                    \For{j=S:n}{
                        \eIf{max($B_{j}$) : max($B_{(j+4)}$)$<$-100}{
                            $E$=j; \tcp*{End Point}
                            Return [$S,E$];
                        }{j++;}
                    }
                }{
                    i++;}
            }
        \end{algorithm}
    \end{figure}

跑出来是这样的
在这里插入图片描述