# Latex使用：在latex中添加算法模块

latex中algorithm模板为：

latex文件中顶端加入的package：

\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{setspace}

\begin{algorithm}[htb]
\setstretch{1.35} %设置具有指定弹力的橡皮长度（原行宽的1.35倍）
\caption{}
\label{alg:Framwork}
\begin{algorithmic}
\REQUIRE ~~\\
The set of positive samples for current batch, $P_n$;\\
The set of unlabelled samples for current batch, $U_n$;\\
Ensemble of classifiers on former batches, $E_{n-1}$;

\ENSURE ~~\\
Ensemble of classifiers on the current batch, $E_n$;
Extracting the set of reliable negative and/or positive samples $T_n$ from $U_n$ with help of $P_n$;\\
\label{ code:fram:extract }

Training ensemble of classifiers $E$ on $T_n \cup P_n$, with help of data in former batches;\\
\label{code:fram:trainbase}

$E_n=E_{n-1}\cup E$;\\

Classifying samples in $U_n-T_n$ by $E_n$;\\
\label{code:fram:classify}

Deleting some weak classifiers in $E_n$ so as to keep the capacity of $E_n$;\\
\label{code:fram:select}

$E_n$;\\
\end{algorithmic}
\end{algorithm}

\documentclass{article}
\usepackage{algorithm2e,setspace}

\begin{document}

\begin{algorithm}
\setstretch{1.35}
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}

\bigskip

\begin{algorithm}
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}

\end{document} 

Latex中的常用算法块如上所述，使用过程中其它技巧可查询之后进行设置。

posted @ 2017-05-26 20:42  Fight boy  阅读(29436)  评论(0编辑  收藏  举报