Latex编辑算法伪代码示例

伪代码:

[plain]  view plain  copy
  1. \documentclass[11pt]{article}  
  2. \usepackage{CJK}  
  3. \usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}  
  4. \usepackage{algorithm}  
  5. \usepackage{algorithmicx}  
  6. \usepackage{algpseudocode}  
  7. \usepackage{amsmath}  
  8. \usepackage{amssymb}  
  9.   
  10. \floatname{algorithm}{Algorithm}  
  11. \renewcommand{\algorithmicrequire}{\textbf{Input:}}  
  12. \renewcommand{\algorithmicensure}{\textbf{Output:}}  
  13.   
  14. \begin{document}  
  15. \begin{CJK*}{UTF8}{gkai}  
  16. %SetUp函数  
  17.     \begin{algorithm}  
  18.         \caption{AlgoName}  
  19.         \begin{algorithmic}[1] %每行显示行号  
  20.         \Require Input  
  21.         \Ensure Output  
  22.   
  23.             \Function {"FuncName"}{}  
  24.                 %if  
  25.                 \If {"condition"}  "text"   \EndIf  
  26.                 \State  
  27.                   
  28.                 % if else  
  29.                 \If  {"condition"}   "text"     
  30.                 \Else   "text"      
  31.                 \EndIf\State                  
  32.                   
  33.                 %if  elseif else  
  34.                 \If  {"condition"}     "text"     
  35.                 \ElsIf {"condition"}   "text"         
  36.                 \Else   "text"    
  37.                 \EndIf\State  
  38.                   
  39.                 %for  
  40.                 \For{"condition"}   "text"   \EndFor\State  
  41.                   
  42.                 %forall  
  43.                 \ForAll {"condition"}  "text"  \EndFor\State  
  44.                   
  45.                 %while  
  46.                 \While {"condition"}  "text"  \EndWhile\State  
  47.                   
  48.                 %repeat  
  49.                 \Repeat "text"  \Until {"condition"}\State  
  50.                   
  51.                 %loop  
  52.                 \Loop "text"  \EndLoop\State  
  53.                 %return  
  54.                 \Return $Result$  
  55.             \EndFunction  
  56.   
  57.         \end{algorithmic}  
  58.     \end{algorithm}  
  59. \end{CJK*}  
  60. \end{document}  

输出结果:



猜你喜欢

转载自blog.csdn.net/weixin_39919527/article/details/79828885