之前自己尝试用visio+mathtype画算法流程图,但是总是存在着各种各样的问题,今天才知道最好的算法流程图是用latex写出来的,在网上找到相关资源,先记录下来,然后照着实践一下看看效果。

转载自:http://blog.csdn.net/u010485913/article/details/50609623

  1. \documentclass{article}
  2. \usepackage{amsmath}
  3. \usepackage{algorithm}
  4. \usepackage{algpseudocode}
  5. \makeatletter
  6. \def\BState{\State\hskip-\ALG@thistlm}
  7. \makeatother
  8. \floatname{algorithm}{Procedure}
  9. \renewcommand{\algorithmicrequire}{\textbf{Input:}}
  10. \renewcommand{\algorithmicensure}{\textbf{Output:}}
  11. \begin{document}
  12. \begin{algorithm}
  13. \caption{My algorithm}\label{euclid}
  14. \begin{algorithmic}[1]
  15. \Procedure{MyProcedure}{}
  16. abc
  17. \State $\textit{stringlen} \gets \text{length of }\textit{string}$
  18. \State $i \gets \textit{patlen}$
  19. \BState \emph{top}:
  20. \If {$i > \textit{stringlen}$} \Return false
  21. \EndIf
  22. \State $j \gets \textit{patlen}$
  23. \BState \emph{loop}:
  24. \If {$\textit{string}(i) = \textit{path}(j)$}
  25. \State $j \gets j-1$.
  26. \State $i \gets i-1$.
  27. \State \textbf{goto} \emph{loop}.
  28. \State \textbf{close};
  29. \EndIf
  30. \State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
  31. \State \textbf{goto} \emph{top}.
  32. \EndProcedure
  33. \end{algorithmic}
  34. \end{algorithm}
  35. \begin{algorithm}[h]
  36. \caption{An example for format For \& While Loop in Algorithm}
  37. \begin{algorithmic}[1]
  38. \For{each $i\in [1,9]$}
  39. \State initialize a tree $T_{i}$ with only a leaf (the root);
  40. \State $T=T\cup T_{i};$
  41. \EndFor
  42. \ForAll {$c$ such that $c\in RecentMBatch(E_{n-1})$}
  43. \label{code:TrainBase:getc}
  44. \State $T=T\cup PosSample(c)$;
  45. \label{code:TrainBase:pos}
  46. \EndFor;
  47. \For{$i=1$; $i<n$; $i++$ }
  48. \State $//$ Your source here;
  49. \EndFor
  50. \For{$i=1$ to $n$}
  51. \State $//$ Your source here;
  52. \EndFor
  53. \State $//$ Reusing recent base classifiers.
  54. \label{code:recentStart}
  55. \While {$(|E_n| \leq L_1 )and( D \neq \phi)$}
  56. \State Selecting the most recent classifier $c_i$ from $D$;
  57. \State $D=D-c_i$;
  58. \State $E_n=E_n+c_i$;
  59. \EndWhile
  60. \label{code:recentEnd}
  61. \end{algorithmic}
  62. \end{algorithm}
  63. \end{document}

转自:http://www.myexception.cn/other/1259942.html

LaTeX算法排版例子

1)首先在导言区加入语句:

\usepackage{algorithm}
\usepackage{algorithmic}

2)例1

\begin{algorithm}
\caption{A}
\label{alg:A}
\begin{algorithmic}
\STATE {set $r(t)=x(t)$}
\REPEAT
\STATE set $h(t)=r(t)$
\REPEAT
\STATE set $h(t)=r(t)$
\UNTIL{B}
\UNTIL{B}
\end{algorithmic}
\end{algorithm}

排版结果如下:

3)例2

\begin{algorithm}
\caption{Calculate $y = x^n$}
\label{alg1}
\begin{algorithmic}
\REQUIRE $n \geq 0 \vee x \neq 0$
\ENSURE $y = x^n$
\STATE $y \Leftarrow 1$
\IF{$n < 0$}
\STATE $X \Leftarrow 1 / x$
\STATE $N \Leftarrow -n$
\ELSE
\STATE $X \Leftarrow x$
\STATE $N \Leftarrow n$
\ENDIF
\WHILE{$N \neq 0$}
\IF{$N$ is even}
\STATE $X \Leftarrow X \times X$
\STATE $N \Leftarrow N / 2$
\ELSE[$N$ is odd]
\STATE $y \Leftarrow y \times X$
\STATE $N \Leftarrow N - 1$
\ENDIF
\ENDWHILE
\end{algorithmic}
\end{algorithm}

排版结果如下:

4)\renewcommand 改变现有命令的定义。在导言区加入如下语句:

\renewcommand{\algorithmicrequire}{ \textbf{Input:}} %Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{ \textbf{Output:}} %UseOutput in the format of Algorithm

使得原来软件包中定义的命令\REQUIRE和\ENSURE显示为Input:和Output:

一个例子如下:

\begin{algorithm}[htb]
\caption{ Framework of ensemble learning for our system.}
\label{alg:Framwork}
\begin{algorithmic}[1] %这个1 表示每一行都显示数字
\REQUIRE ~~\\ %算法的输入参数:Input
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 ~~\\ %算法的输出:Output
Ensemble of classifiers on the current batch, $E_n$;
\STATE Extracting the set of reliable negative and/or positive samples $T_n$ from $U_n$ with help of $P_n$;
\label{ code:fram:extract }%对此行的标记,方便在文中引用算法的某个步骤
\STATE Training ensemble of classifiers $E$ on $T_n \cup P_n$, with help of data in former batches;
\label{code:fram:trainbase}
\STATE $E_n=E_{n-1}\cup E$;
\label{code:fram:add}
\STATE Classifying samples in $U_n-T_n$ by $E_n$;
\label{code:fram:classify}
\STATE Deleting some weak classifiers in $E_n$ so as to keep the capacity of $E_n$;
\label{code:fram:select}
\RETURN $E_n$; %算法的返回值
\end{algorithmic}
\end{algorithm}

排版结果如下:

5)最后一个例子

\begin{algorithm}[h]
\caption{An example for format For \& While Loop in Algorithm}
\begin{algorithmic}[1]
\FOR{each $i \in [1,9]$}
\STATE initialize a tree $T_{i}$ with only a leaf (the root);\
\STATE $T=T \cup T_{i};$\
\ENDFOR
\FORALL {$c$ such that $c \in RecentMBatch(E_{n-1})$}
\label{code:TrainBase:getc}
\STATE $T=T \cup PosSample(c)$;
\label{code:TrainBase:pos}
\ENDFOR
\FOR{$i=1$; $i<n$; $i++$ }
\STATE $//$ Your source here;
\ENDFOR
\FOR{$i=1$ to $n$}
\STATE $//$ Your source here;
\ENDFOR
\STATE $//$ Reusing recent base classifiers.
\label{code:recentStart}
\WHILE {$(|E_n| \leq L_1 )and( D \neq \phi)$}
\STATE Selecting the most recent classifier $c_i$ from $D$;
\STATE $D=D-c_i$;
\STATE $E_n=E_n+c_i$;
\ENDWHILE
\label{code:recentEnd}
\end{algorithmic}
\end{algorithm}

排版结果如下:

LaTex论文排版 | (18)算法流程图(伪代码)相关推荐

  1. Latex论文排版——图片

    LaTex 论文排版: 1.一般图片插入 导言区 \usepackage{graphicx} % insert graphic 1 正文 \begin{figure*} \includegraphic ...

  2. LaTex 论文排版(4): 插入图片(Visio图转换成.eps图)

    目录 1 简要步骤 2 示例 使用LaTex 排版时,需要插入图片,格式可以为.png, .tif, .bmp, .eps等,其中.eps格式最好的,这样去生成pdf的图片是非常清晰的.我们一般使用V ...

  3. 【githubboy】数学建模学习资源,包含数学建模相关的算法、LaTeX 论文模板、算法思维导图

    在 GitHub 开源了数学建模学习资源,主要包含数学建模相关的竞赛优秀论文.算法.LaTeX 论文模板.算法思维导图.书籍.Matlab 教程等内容. GitHub:github.com/zhanw ...

  4. LaTex 论文排版(3): 插入参考文献

    使用LaTex 排版时,需要插入参考文献.如下图,使用IEEE Transactions 的模板,但是参考文献的设置实在是太麻烦,如下图所示,很多东西都要单独分出来,很不方便.也不便于修改,非常消耗时 ...

  5. (转载)LaTex 论文排版(1): Win10 下 LaTex所需软件安装 (Tex live 2018 + Tex studio)

    版权声明:本文为CSDN博主「TechXYM」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明. 原文链接:https://blog.csdn.net/zaishu ...

  6. latex论文排版个人向相关问题记录

    很久没更新了,小论文基本都见刊了,记录下之前写论文碰上的latex一些排版问题吧,比较琐碎. 伪代码跨页问题 最开始使用algorithms包来写的伪代码,左边会有大方括号,蛮好看的. 不过使用alg ...

  7. latex 参考文献没有显示_甜甜的磕盐路 | LaTeX论文排版小贴士

    號 外 管院日报 甜甜的嗑盐路 经历了充实而又紧张的论文撰写后 童鞋们肯定都拥有了干货满满的论文初稿 接下来的难题将聚焦于-- "啊啊啊,我的页码怎么一直对不上啊" "为 ...

  8. word论文排版:算法伪代码带行号竖线以及多竖线的模板分享

    文档分享链接: https://pan.baidu.com/s/1F_wxPeP25UM0LeEsTf1SAw?pwd=ex1b 提取码:ex1b

  9. LaTex论文排版 | (16)绘制程序流程图(框图)

    在写作论文时,流程图是一种最为直观和直接的方法来帮助我们表示思想方法或者算法.下面介绍一种使用 LaTeX 宏包 TikZ 来绘制矢量流程图的方法,主要参考了这篇博客 Ethan Deng 基本步骤 ...

  10. Latex论文排版技巧再总结

    1.Q:几个作者同时共享机构地址,怎么搞? A:拿ACM的模版为例, Yes, and we suggest you do the following... Insert this piece of ...

最新文章

  1. layui遍历json数组_Python列表边遍历边删除,怎么用才不报越界错误呢?
  2. 将本地SHH文件导入SourceTree配置
  3. 解决windows找不到D:launcher\launcher.exe的方法
  4. 关于U打包代码必须放到Editor目录下的问题
  5. python中cumsum_在python里“np.cumsum”这个命令是干什么的?怎么使用?
  6. 深入浅出谈CUDA(二)
  7. tpc-c 服务器性能,IBM创英特尔8处理器服务器TPC-C性能记录
  8. 2022年6月25日PMP考试通关宝典-5
  9. sigmoid/softmax指数运算溢出问题的解决方法
  10. 【程序人生】Web前端工程师岗位分析报告
  11. mysql查询条件为空时不作为条件_怎么实现当查询值为空时,不作为查询条件
  12. 从博弈论看高薪行业岗位
  13. 安全专业委员会发言_企业安全委员会发言
  14. 小学一年级语文心田花开各类词汇用法汇总
  15. 用代码抗议996加班:集结在github上的程序员,正在进行一场社会实验
  16. 关于微服务的三个厄运问题
  17. 1009 type C 与DP检测,USB3.0与PD协议
  18. transE论文阅读 19年记录的
  19. 使用html设计商业网站试题,电子商务师网页设计与制作试题
  20. 对话框AlertDialog的使用

热门文章

  1. weblogic 自定义错误页面_使用 Nginx 容器为 Traefik 配置高性能通用错误页面
  2. python更换镜像源_更换Anaconda 和 Pip 镜像源的方法
  3. qt制作漂亮的登录界面,仅供参考
  4. qt实现抽屉效果,类似qq的好友功能
  5. 类对象和类指针以及类的内存分布
  6. ubuntu 如何编译 java_在ubuntu中编译运行java程序
  7. Java版扫雷小游戏
  8. PDF加密、解密内幕(三) -破解加密PDF文件
  9. SQL Server Storage
  10. 织梦友情链接html,总结dedecms怎么调用友情链接的方法[全]