Latex使用:在latex中添加算法模块
Posted Fight boy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Latex使用:在latex中添加算法模块相关的知识,希望对你有一定的参考价值。
在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入门》也可以得到很好解决。
以上是关于Latex使用:在latex中添加算法模块的主要内容,如果未能解决你的问题,请参考以下文章