使用algorithmicx包
egin{algorithm} caption{Sum of integers from 1 to n.} egin{algorithmic}[1] Procedure {Sum}{$n$} State $sum gets 0 hfill riangleright { m Initialization}$ For{$i gets 1,n$} State $sum gets sum + i$ EndFor State Return{$sum$} $ hfill riangleright { m Return}$ EndProcedure end{algorithmic} end{algorithm}
结果如下: