Latex_算法
1.0.0
问题1:如何删除算法标题中的算法编号?
解决方案:在begin{algorithm}
之后添加renewcommand{thealgorithm}{}
请参阅示例 Latex 文件 Algorithm_caption_no_number.tex 及其 PDF 输出
documentclass[11pt]{article}
usepackage{algorithmicx}
usepackage{algorithm}
usepackage{algpseudocode}
begin{document}
begin{algorithm}
renewcommand{thealgorithm}{}
caption{Test Algorithm}label{euclid}
begin{algorithmic}[1]
Procedure{Euclid}{$a,b$}Comment{The g.c.d. of a and b}
State $rgets abmod b$
While{$rnot=0$}Comment{We have the answer if r is 0}
State $agets b$
State $bgets r$
State $rgets abmod b$
EndWhilelabel{euclidendwhile}
State textbf{return} $b$Comment{The gcd is b}
EndProcedure
end{algorithmic}
end{algorithm}
end{document}
问题 2:如何删除算法主体中的行号?
解决方案:
defNoNumber#1{{defalglinenumber##1{}State #1}addtocounter{ALG@line}{-1}}
NoNumber{}
中请参阅示例 Latex 文件 Algorithm_line_no_number.tex 及其 PDF 输出
documentclass[11pt]{article}
usepackage{algorithmicx}
usepackage{algorithm}
usepackage{algpseudocode}
usepackage{color}
defNoNumber#1{{defalglinenumber##1{}State #1}addtocounter{ALG@line}{-1}}
begin{document}
begin{algorithm}
caption{Test Algorithm}label{euclid}
begin{algorithmic}[1]
Procedure{Euclid}{$a,b$}Comment{The g.c.d. of a and b}
State $rgets abmod b$
While{$rnot=0$}Comment{We have the answer if r is 0}
State $agets b$
State $bgets r$
State $rgets abmod b$
EndWhilelabel{euclidendwhile}
State textbf{return} $b$Comment{The gcd is b}
NoNumber{color{red} This line will not have a number!}
EndProcedure
end{algorithmic}
end{algorithm}
end{document}