我的問題類似於這個,我需要跳過演算法的某些行的數字。然而,這個問題的解決方案對我來說不起作用。如何使用該algorithmic
包禁用某些線路的號碼?
這是我嘗試過的:
\documentclass{article}
\usepackage{algorithmic}
\usepackage{algorithm}
\def\NoNumber#1{{\def\alglinenumber##1{}\State #1}\addtocounter{ALG@line}{-1}}
\begin{document}
\begin{algorithmic}[1]
\STATE Compute $Pr(X_i < x)$ and $Pr(x < X_i)$ for all $i = 1, \dots, M$ and
\FOR {$i = 1, \dots, n$}
\STATE with a number
\NoNumber{ without number}
\ENDFOR
\end{algorithmic}
\end{document}
答案1
一種選擇是使用更通用的algorithmicx
包及其algcompatible
格式(允許您使用algorithmic
語法);您可以用於 \STATEx
未編號的行:
\documentclass{article}
\usepackage{algcompatible}
\begin{document}
\begin{algorithmic}[1]
\IF{some condition is true}
\STATE do some processing
\ELSIF{some other condition is true}
\STATEx do some different processing
\ELSIF{some even more bizarre condition is met}
\STATEx do something else
\ELSE
\STATE do the default actions
\ENDIF
\end{algorithmic}
\end{document}
當然,只有當您已經使用該語法編寫演算法並且希望在不造成重大創傷的情況下切換時,algcompatible
才建議使用;如果您剛開始編寫演算法,請從頭開始使用以下格式:algorithmic
algorithmicx
algpseudocode
\documentclass{article}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithmic}[1]
\If{some condition is true}
\State do some processing
\ElsIf{some other condition is true}
\Statex do some different processing
\ElsIf{some even more bizarre condition is met}
\Statex do something else
\Else
\State do the default actions
\EndIf
\end{algorithmic}
\end{document}
答案2
新增一個空白行作為換行符,然後在下一行中寫入您想要的任何內容:
\documentclass{article}
\usepackage{algorithmic}
\usepackage{algorithm}
\def\NoNumber#1{{\def\alglinenumber##1{}\State #1}\addtocounter{ALG@line}{-1}}
\begin{document}
\begin{algorithmic}[1]
\STATE Compute $Pr(X_i < x)$ and $Pr(x < X_i)$ for all $i = 1, \dots, M$ and
\FOR {$i = 1, \dots, n$}
\STATE with a number
without number
\ENDFOR
\end{algorithmic}
\end{document}