在Miktex下有三個latex algorithm包,分別為:algorithm,algorithmic,algorithm2e三個,其中algorithm,algorithmic經常成套使用:
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$;\\ \label{code:fram:add} 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}
實際算法結果圖示為:
第二種用法:
使用algorithm2e包進行處理
\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}{ read current\; \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}{ read current\; \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中的常用算法塊如上所述,使用過程中其它技巧可查詢之后進行設置。
上述記錄僅用來對latex使用過程中的心得體會進行總結。
個人感悟:寫latex一定要靜下心,要不然很容易出現低級錯誤。遇到不會的格式或方法,勤用搜索引擎去尋找答案。
其實在這里自己是被行距問題卡了很長時間,遇到的問題是因為算法的行距太小:
行距問題的設置網絡搜索就可以解決,查閱劉海洋的《latex入門》也可以得到很好解決。