![標題中帶有過程的偽代碼](https://rvso.com/image/370691/%E6%A8%99%E9%A1%8C%E4%B8%AD%E5%B8%B6%E6%9C%89%E9%81%8E%E7%A8%8B%E7%9A%84%E5%81%BD%E4%BB%A3%E7%A2%BC.png)
我正在嘗試使用類似於的偽代碼本文。我目前正在使用演算法包。我的問題是我希望標題如下所示:
所以大寫並帶有參數。我似乎不知道該怎麼做。下面是一個例子。基本上我希望「Euclid(a,b)」出現在標題中,而不是後面的正文中程式。
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\floatname{algorithm}{Procedure}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\renewcommand\thealgorithm{}
\begin{document}
\begin{algorithm}
\caption{Euclid’s algorithm}
\begin{algorithmic}[1]
\Require Integers $a$ and $b$
\Ensure The g.c.d of $a$ and $b$
\Procedure{Euclid}{$a,b$}
\State $r\gets a\bmod b$
\While{$r\not=0$}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile
\State \textbf{return} $b$
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
訣竅是使用\textproc
,如下所示:
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\floatname{algorithm}{Procedure}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\renewcommand\thealgorithm{}
\begin{document}
\begin{algorithm}
\caption{\textproc{Euclid}$(a,b)$}
\begin{algorithmic}[1]
\Require Integers $a$ and $b$
\Ensure The g.c.d of $a$ and $b$
\State $r\gets a\bmod b$
\While{$r\not=0$}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile
\State \textbf{return} $b$
\end{algorithmic}
\end{algorithm}
\end{document}
順便說一句,當您希望這樣做時,這也很有用參考文中的一個演算法。