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}