LaTeX 算法代码排版 --latex2e范例总结
LaTeX 写作: 算法代码排版 --latex2e范例总结
latex2e 宏包的使用范例:
- \usepackage[ruled]{algorithm2e} %算法排版样式1
- \usepackage[ruled,vlined]{algorithm2e} %算法排版样式2
- \usepackage[linesnumbered,boxed]{algorithm2e} %算法排版样式3
使用上述代码中三种不同的宏包编译后的代码排版样式预览:
样式一:
样式二:
样式三:
latex代码排版.tex文件:
\documentclass{article}
\usepackage[ruled]{algorithm2e} %算法排版样式1
%\usepackage[ruled,vlined]{algorithm2e} %算法排版样式2
%\usepackage[linesnumbered,boxed]{algorithm2e} %算法排版样式3
\begin{document} How to use the algorithm2e in \LaTeX ~ file. Examples:
% ------------------------------Example - ---------------------------------------------
\begin{algorithm}[H]
\caption{How to write algorithms}
\KwIn{this text}
\KwOut{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\;
}
}
\end{algorithm} % ---------------------------Example - ------------------------------------------------
\begin{algorithm}
% \SetAlgoNoLine %去掉之前的竖线
\caption{identifyRowContext}
\KwIn{$r_i$, $Backgrd(T_i)$=${T_1,T_2,\ldots ,T_n}$ and similarity threshold $\theta_r$}
\KwOut{$con(r_i)$}
$con(r_i)= \Phi$\;
\For{$j=;j \le n;j \ne i$}
{
float $maxSim=$\;
$r^{maxSim}=null$\;
\While{not end of $T_j$}
{
compute Jaro($r_i,r_m$)($r_m\in T_j$)\;
\If{$(Jaro(r_i,r_m) \ge \theta_r)\wedge (Jaro(r_i,r_m)\ge r^{maxSim})$}
{
replace $r^{maxSim}$ with $r_m$\;
}
}
$con(r_i)=con(r_i)\cup {r^{maxSim}}$\;
}
return $con(r_i)$\;
\end{algorithm}
%--------------------------------------------------------------------------------------
some special information
The algorithm2e LaTeX package conflicts with several others over the use of the algorithm identifier. A common indicator is something like this message:
To resolve the issues, simply put the following just before the inclusion of the algorithm2e package: %\makeatletter
%\newif\if@restonecol
%\makeatother
%\let\algorithm\relax
%\let\endalgorithm\relax \end{document}
中文latex模式下,更改Input为输入,更改Output为输出的方法: 在算法内部插入、
\SetKwInOut{KIN}{输入}
\SetKwInOut{KOUT}{输出}
用我们定义的新的宏名“\KIN” 在算法开头相应位置替换掉自带的\KwInput,用"\KOUT" 替换掉\KwOutput 即可,实现中文的输入和输出.
具体事例如下:
\renewcommand{\algorithmcfname}{算法}
\begin{algorithm}[H]
%\SetAlgoNoLine
4 \SetKwInOut{KIN}{输入}
5 \SetKwInOut{KOUT}{输出}
%\BlankLine %空一行
\caption{标准DE算法 }
\label{DE_algo} %
\KIN{Population: $ M$; Dimension: $ D $; Genetation: $ T $ }
\KOUT{The best vector (solution) $ \varDelta $ }
$ t \leftarrow (initialization) $\;
\For{$i=$ to $ M $ }
{\For{$j=$ to $ D $}
{
$ {x}_{i,t}^j=x_{min}^j + rand(,)\cdotp (x_{max}^j-x_{min}^j) $\;
}
}
%--------------------------------------------------
\While{$(|f(\varDelta)| \geq\varepsilon )$ or $(t \leq T )$}
{
\For{$ i=$ to $M$}
{
\emph{$ \blacktriangleright $ (Mutation and Crossover)}\\
%\textit{ $ \blacktriangleright $ (Mutation and Crossover) }\\
\For{$j=$ to $ D $}
{
$ v_{i,t}^j =Mutation(x_{i,t}^j)$\;
$ u_{i,t}^j =Crossover(x_{i,t}^j,v_{i,t}^j)$\;
}
\emph{$ \blacktriangleright $ (Greedy Selection)}\\
%\textit{ $ \blacktriangleright $ (Greedy Selection) }\\
\eIf{$ f(\textbf{u}_{i,t}) < f(\textbf{x}_{i,t}) $}
{
$ \textbf{x}_{i,t} \leftarrow\textbf{u}_{i,t}$\;
\If{$ f(\textbf{x}_{i,t}) < f(\varDelta)$}
{
$ \varDelta \leftarrow \textbf{x}_{i,t}$ \;
}
}
{
$ \textbf{x}_{i,t} \leftarrow \textbf{x}_{i,t} $\;
}
}
$ t \leftarrow t+ $\;
} %While
\Return the best vector $\varDelta$\;
\end{algorithm}
LaTeX 算法代码排版 --latex2e范例总结的更多相关文章
- Latex 算法过长 分页显示方法
参考: Algorithm tag and page break Latex 算法过长 分页显示方法 1.引用algorithm包: 2.在\begin{document}前加上以下Latex代码: ...
- latex算法步骤如何去掉序号
想去掉latex算法步骤前面的序号,如下 我想去掉每个算法步骤前面的数字序号,1,2,3,因为我已经写了step.我们只需要引用a lgorithmic这个包就可以了,代码如下: \usepackag ...
- KMP算法代码
以下是本人根据上一篇博客随笔http://www.cnblogs.com/jiayouwyhit/p/3251832.html,所写的KMP算法代码(暂未优化),个人认为在基于上一篇博客的基础上,代码 ...
- 算法代码[置顶] 机器学习实战之KNN算法详解
改章节笔者在深圳喝咖啡的时候突然想到的...之前就有想写几篇关于算法代码的文章,所以回家到以后就奋笔疾书的写出来发表了 前一段时间介绍了Kmeans聚类,而KNN这个算法刚好是聚类以后经常使用的匹配技 ...
- swift代码排版-参考
代码排版包括: 空行.空格.断行和缩进等内容.代码排版内容比较多工作量很多,但是非常重要. 空行 空行将逻辑相关的代码段分隔开,以提高可读性.下列情况应该总是添加空行: 类型声明之前. import语 ...
- 经常使用MD5算法代码
经常使用的MD5算法代码日期: 2014年8月4日作者: 铁锚 MD5,全称为 Message Digest Algorithm 5(消息摘要算法第五版).详情请參考 维基百科:MD5 MD5加密后 ...
- 带你找到五一最省的旅游路线【dijkstra算法代码实现】
算法推导过程参见[dijkstra算法推导详解] 此文为[dijkstra算法代码实现] https://www.cnblogs.com/Halburt/p/10767389.html package ...
- L3-019 代码排版 (30 分)
某编程大赛中设计有一个挑战环节,选手可以查看其他选手的代码,发现错误后,提交一组测试数据将对手挑落马下.为了减小被挑战的几率,有些选手会故意将代码写得很难看懂,比如把所有回车去掉,提交所有内容都在一行 ...
- LDPC译码算法代码概述
程序说明 V0.0 2015/1/24 LDPC译码算法代码概述 概述 本文介绍了包括LDPC_Simulation.m, ldpcdecoderbp1.m,ldpcdecoderminsum ...
随机推荐
- jsonp的三种跨域方式
1.通过jq的$.ajax()完成跨域,这是我比较喜欢的一种方式. 代码如下: $.ajax({ type:'get', async:true, url:'地址', dataType:'jsonp', ...
- jsrender-for循环中访问父属性
jsrender中使用for循环数据时有时需要访问父级数据. 而jsrender在循环中的父级数据存放在隐藏属性parent.parent.data中,使用案例如下 {{:#parent.parent ...
- spring3使用task:annotation-driven开始定时
先看一个案例 package com.jCuckoo.demo; import java.text.SimpleDateFormat; import java.util.Date; import or ...
- css 去除 a,checkbox 框 出现虚线
在开发过程中遇到checkbox框,第一次遇到还以为是系统自带的是这样 后来发现不是那样, 我们可以在使用css 去掉出现的虚线框,以下是我的解决方案代码: /* checkbox 去掉虚框*/:fo ...
- javaweb项目打包成war包
从来没有想过web项目还能打包的,但是有要求,就不得不去实现,在网上找了一下,发现挺简单的. 首先是使用MyEclipse将web项目打包,如下图所示. 右键选中项目,选择export. 然后选择J2 ...
- Tomcat访问日志详细配置
在server.xml里的<host>标签下加上 <Valve className="org.apache.catalina.valves.AccessLogValve&q ...
- 基本概率分布Basic Concept of Probability Distributions 8: Normal Distribution
PDF version PDF & CDF The probability density function is $$f(x; \mu, \sigma) = {1\over\sqrt{2\p ...
- RNN 入门教程 Part 2 – 使用 numpy 和 theano 分别实现RNN模型
转载 - Recurrent Neural Networks Tutorial, Part 2 – Implementing a RNN with Python, Numpy and Theano 本 ...
- Mysql 列转行统计查询 、行转列统计查询
-- ---------------------------- -- Table structure for `TabName` -- ---------------------------- D ...
- POJ3292 Semi-prime H-numbers
传送门: 刷<数论一本通>时看到的题,简单记录一下. 题目大意(照抄书上的):形如4n+1的数被称为H数,乘法在H数组成的集合内是封闭的.在这个集合中是能被1和本身整除的数叫H-素数,其余 ...