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 - 1---------------------------------------------\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 - 2------------------------------------------------\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=1;j \le n;j \ne i$} { float $maxSim=0$\; $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 informationThe 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}

原文:

http://www.cnblogs.com/tsingke/p/5833221.html

\documentclass{article}
\usepackage{CJK}

\usepackage[noend]{algpseudocode}
\usepackage{algorithmicx,algorithm}

\begin{document}

\begin{algorithm}[t]
\caption{algorithm caption} %算法的名字
\hspace*{0.02in} {\bf Input:} %算法的输入, \hspace*{0.02in}用来控制位置,同时利用 \\ 进行换行
input parameters A, B, C\\
\hspace*{0.02in} {\bf Output:} %算法的结果输出
output result
\begin{algorithmic}[1]
\State some description % \State 后写一般语句
\For{condition} % For 语句,需要和EndFor对应
  \State ...
  \If{condition} % If 语句,需要和EndIf对应
    \State ...
  \Else
    \State ...
  \EndIf
\EndFor
\While{condition} % While语句,需要和EndWhile对应
  \State ...
\EndWhile
\State \Return result
\end{algorithmic}
\end{algorithm}

\begin{algorithm}[t] \caption{algorithm caption} %算法的名字 \hspace*{0.02in} {\bf Input:} %算法的输入, \hspace*{0.02in}用来控制位置,同时利用 \\ 进行换行 input parameters A, B, C\\ \hspace*{0.02in} {\bf Output:} %算法的结果输出 output result \begin{algorithmic}[1] \State some description % \State 后写一般语句 \For{condition} % For 语句,需要和EndFor对应\State ...\If{condition} % If 语句,需要和EndIf对应\State ...\Else\State ...\EndIf \EndFor \While{condition} % While语句,需要和EndWhile对应\State ... \EndWhile \State \Return result \end{algorithmic} \end{algorithm}

\end{document}

LaTeX 写作: 算法代码排版 --latex2e范例总结相关推荐

  1. LaTeX 算法代码排版 --latex2e范例总结

    LaTeX 写作: 算法代码排版 --latex2e范例总结 latex2e 宏包的使用范例: \usepackage[ruled]{algorithm2e}                     ...

  2. LaTex算法代码排版-algorithm2e

    LaTex算法代码排版-algorithm2e 1.使用如下宏包 2.示例代码 3.生成效果 4.参考链接 1.使用如下宏包 \usepackage[ruled]{algorithm2e} %带竖线 ...

  3. 【Latex】算法排版规律(中文排版)

    参考资料: <algorithm, algorithmic算法包到底什么区别?> <Latex写算法的伪代码排版> <Latex 编写算法伪代码,基于algorithmi ...

  4. LaTex:算法排版

    排版可能需要的包: usepackage{algorithm} //format of the algorithm usepackage{algorithmic} //format of the al ...

  5. [LaTeX] 用minipage来排版多张图片(子图片)! (以及用subfigure而不是subfloat来排版代码型图片)

    文章目录 前言 1 代码 2 小结 3 补充:用subfigure而不是subfloat来排版代码型图片 前言 上一篇写了[LaTeX] 字图片复杂排版的博客,刚刚找到了更好更简洁方便的方法!完全可以 ...

  6. 【LaTeX】算法伪代码 ——代码实例、字体大小设置、显示问题

    1. 算法伪代码 \documentclass[AMA,STIX1COL]{WileyNJD-v2} \usepackage{moreverb}\begin{algorithm}[p] \small ...

  7. vscode只有utf8_基于VSCode搭建LaTeX写作环境

    前言 由于要进行毕业设计,配置了一套VSCode环境以便于"优雅的"书写代码和论文 LaTeX常用于排版学术论文,它可以让我们专心于内容而不用费心于排版或字体.LateX有TeX ...

  8. VScode latex 写作小结

    用VSCODE写latex有一段时间了,给写作增加了不少乐趣,确切地说,降低了不少写作的痛苦.其中也遇到了一些问题,这里将常见的问题小结一下 图片表格显示位置错乱 这个原因排版系统自身的原因,可能是为 ...

  9. LaTeX写作之中译英/英文语法纠正

    一.思路 科研人员,比如英语水平一般的我,常常需要用到中文到English的机器翻译.然而,在LaTeX写作时,行内引用和行内公式提高了机器翻译的难度,同时也降低了机器翻译的精度,进而影响我们写作的速 ...

最新文章

  1. Windows server 2008 r2企业版安装步骤
  2. 在项目中常用到的几个注解@JsonInclude、@JsonFormat、@DateTimeFormat
  3. step4 . day3 目录访问函数
  4. [图]罗技推出背光键盘
  5. 【debug】使用lambda在循环中传参时,参数总为同一个值
  6. STM32的优先级NVIC_PriorityGroupConfig的理解及其使用(转)
  7. sftp 设置仅能访问自己目录的用户
  8. 前端基础7:a标签常用方法和元素居中方式,响应式@media
  9. C++基础:C++的封装/继承/多态
  10. python精简总结
  11. k8s组件通信或者创建pod生命周期
  12. LINUX下载编译YASM
  13. 全网最全AE中英文界面对照表分享
  14. 版式设计优秀作品欣赏_垂直版式的垂直作品设计探索
  15. WebService-服务端与客户端
  16. 层次分析法(AHP)原理_例题应用及代码
  17. 华东交通大学计算机专业分数,往年华东交通大学优势专业排名及分数线参考
  18. python中e怎么计算_蒙特卡洛法计算自然常数e——python编程及可视化
  19. 数字乡村数据库:农村农业数字化指标、县域数字乡村指数、中国电子商务报告等四大维度数据
  20. 我们不仅仅做软件 云工作台+ 聚合·共享

热门文章

  1. java判断日期前后_Java丨时间判断谁前谁后
  2. 入门系列-集成 Autofac
  3. pycharm中导入pyQt无法使用
  4. Mac用Xcode建立TCP和UDP Socket(套接字)编程
  5. Win系统蓝牙设备删除失败 - 解决方案
  6. 苹果推出iPhone 12维修计划,解决无声音问题
  7. 【unity3d】如何学习unity3d
  8. RAID的几种工作模式
  9. 如何使用Logitech Harmony遥控器控制智能家居设备
  10. 河海大学计算机网络毕业设计,河海大学文件河海大学毕业设计.doc