简介
LaTeX(LATEX,音译“拉泰赫”)是一种基于ΤΕΧ的排版系统,由美国计算机学家莱斯利·兰伯特(Leslie Lamport)在20世纪80年代初期开发,利用这种格式,即使使用者没有排版和程序设计的知识也可以充分发挥由TeX所提供的强大功能,能在几天,甚至几小时内生成很多具有书籍质量的印刷品。对于生成复杂表格和数学公式,这一点表现得尤为突出。因此它非常适用于生成高印刷质量的科技和数学类文档。这个系统同样适用于生成从简单的信件到完整书籍的所有其他种类的文档。
模板1
代码语言:javascript复制documentclass[11pt]{article}
usepackage{CJK}
usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
usepackage{algorithm}
usepackage{algorithmicx}
usepackage{algpseudocode}
usepackage{amsmath}
usepackage{amssymb}
floatname{algorithm}{Algorithm}
renewcommand{algorithmicrequire}{textbf{Input:}}
renewcommand{algorithmicensure}{textbf{Output:}}
begin{document}
begin{CJK*}{UTF8}{gkai}
%SetUp函数
begin{algorithm}
caption{算法整体框架}
begin{algorithmic}[1] %每行显示行号
%Require Input
%Ensure Output
State $种群 gets 0$
Function {"FuncName"}{}
%if
If {"condition"} "text" EndIf
State
% if else
If {"condition"} "text"
Else "text"
EndIfState
%if elseif else
If {"condition"} "text"
ElsIf {"condition"} "text"
Else "text"
EndIfState
%for
For{"condition"} "text" EndForState
%forall
ForAll {"condition"} "text" EndForState
%while
While {"condition"} "text" EndWhileState
%repeat
Repeat "text" Until {"condition"}State
%loop
Loop "text" EndLoopState
%return
Return $Result$
EndFunction
end{algorithmic}
end{algorithm}
end{CJK*}
end{document}
效果:
模板2
代码语言:javascript复制documentclass[11pt]{article}
usepackage{CJK}
usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
usepackage{algorithm}
usepackage{algorithmicx}
usepackage{algpseudocode}
usepackage{amsmath}
floatname{algorithm}{算法}
renewcommand{algorithmicrequire}{textbf{输入:}}
renewcommand{algorithmicensure}{textbf{输出:}}
begin{document}
begin{CJK*}{UTF8}{gkai}
begin{algorithm}
caption{用归并排序求逆序数}
begin{algorithmic}[1] %每行显示行号
Require $Array$数组,$n$数组大小
Ensure 逆序数
Function {MergerSort}{$Array, left, right$}
State $result gets 0$
If {$left < right$}
State $middle gets (left right) / 2$
State $result gets result $ Call{MergerSort}{$Array, left, middle$}
State $result gets result $ Call{MergerSort}{$Array, middle, right$}
State $result gets result $ Call{Merger}{$Array,left,middle,right$}
EndIf
State Return{$result$}
EndFunction
State
Function{Merger}{$Array, left, middle, right$}
State $igets left$
State $jgets middle$
State $kgets 0$
State $result gets 0$
While{$i<middle$ textbf{and} $j<right$}
If{$Array[i]<Array[j]$}
State $B[k ]gets Array[i ]$
Else
State $B[k ] gets Array[j ]$
State $result gets result (middle - i)$
EndIf
EndWhile
While{$i<middle$}
State $B[k ] gets Array[i ]$
EndWhile
While{$j<right$}
State $B[k ] gets Array[j ]$
EndWhile
For{$i = 0 to k-1$}
State $Array[left i] gets B[i]$
EndFor
State Return{$result$}
EndFunction
end{algorithmic}
end{algorithm}
end{CJK*}
end{document}
效果:
LaTeX在线编辑
https://www.overleaf.com/
参考
https://www.cnblogs.com/hqium/p/6439312.html