1. 程式人生 > >Latex插入虛擬碼

Latex插入虛擬碼

%\floatname{algorithm}{Alg. }%自己命名首行開頭顯示內容
\renewcommand{\algorithmicrequire}{\textbf{Input:}}%Input
\renewcommand{\algorithmicensure}{\textbf{Output:}}%Output
\begin{center}
\begin{minipage}{0.8\textwidth}%寬度調整
\begin{algorithm}[H]
%\footnotesize%字型大小
\caption{One Greedy Algorithm}%首行顯示演算法名稱
\begin{algorithmic}[1]%行編號,從Input, Output後面開始
\Require Point Set $P\subseteq \mathbb{R}^{d}$; the threshold $\delta$.%輸入Input
\Ensure A subset $U$ of $P$.                                           %輸入Output
\For{$t=1$ to $T$}
\If {$t=1$}
\State Initialize the classifier with parameter set $w_1$
\ElsIf {$t=2$}
\State Store target observation corresponding to $z_t$
\Else
\State $t\leftarrow t+1$
\EndIf
\EndFor
\end{algorithmic}  
\end{algorithm}
\end{minipage}
\end{center}

顯示結果為