latex写算法伪代码

第一次用latex写算法伪代码,竟然遇到挺多不是很快就能解决的问题······表示很伤神好吗,记录总结一下帮助后来者

导言区

\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}  % 这个和algorithmic不兼容,用了就要报错,好多莫名其妙的错误!!!!!
\renewcommand{\algorithmicrequire}{ \textbf{Input:}}     %Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{ \textbf{Output:}}    %UseOutput in the format of Algorithm

亲身多次测试发现,algorithmic包和algpseudocode不兼容,网上也有人这么说,导言区同时用这俩会报错

而应该用algorithmicx和algpseudocode搭配,可以得到干净清爽的 Process exited normally,并且下面写算法时各种命令都是驼峰式大写,不是全大写(反而识别不了 unrecognized command)

但是正文写算法的地方还是用的algorithmic哦

注意$美元符号在伪代码环境里用的特别多,如果漏掉也是会报错的,还不容易检查到,毕竟latex报的错总是让人觉得异常懵逼,完全无法起到提示修改方向的作用,应该不止我一个人这么觉得吧,有时会超级抓狂

\begin{algorithm}
	\caption{HHS \cite{Branch1998}}
	\label{hhsa}
	\begin{algorithmic}[1]  %1表示每隔一行编号	
		\Require The original signal $x$.
		\Ensure  The energy-time-frequency distribution of $x$. 
		\Function{EMD}{$x, seg\_len$}
		\State $ N \gets length(x) / seg\_len$;
		\For {$i=1 \to i=N$}
		\State $seg(i) \gets x(1+(i-1)*seg\_len : i*seg\_len)$;
		\EndFor
		\EndFunction
	\end{algorithmic}
\end{algorithm}

在这里插入图片描述

seg_len中的下划线要用\_哦

procedure 和function

在这里插入图片描述
具体区别我没研究,可以看看这个网页

调用格式是一样的,都要俩花括号,第一个放name,第二个放parameters,格式不对又是一堆错

\Function{EMD}{$x, SegLen, MaxNumOfImf$}
\EndFunction
\Procedure{EMD}{$x, SegLen, MaxNumOfImf$}
\EndProcedure
  • 17
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值