Latex中加入算法伪代码模板

写论文经常需要加入伪代码,伪代码在Latex中是一个模块,需要先引用几个包,然后在使用相应的指令来写:
1、在Latex头部加入以下包的引用:

\usepackage{algorithm}  
\usepackage{algpseudocode}  
\usepackage{amsmath}  
\renewcommand{\algorithmicrequire}{\textbf{Input:}}  % Use Input in the format of Algorithm  
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm  

2、在正文中添加如下代码:

\begin{algorithm}[htb]  
  \caption{Title}  
  \label{alg:Framwork}  
  \begin{algorithmic}  
    \Require  
    xxxxxxxx 
    \Ensure  
   xxxxxxxxx
      \For{xyz}
      \If {yyyyyyy}  
      \State asdfghjkl;
      \Else
      \State qwertyuiop;
       \If{zzzzzzz}
             \State zxcvbnm;
       \EndIf
      \EndIf
   \EndFor  
    \For {abc }  
      \State qazwsxedc; 
    \EndFor
  \end{algorithmic}  
\end{algorithm}

效果:
这里写图片描述

猜你喜欢

转载自blog.csdn.net/u010682375/article/details/80484666