问题描述
使用algorithmic包时,能够使用的声明是有限的,比如Require,Ensure等。但有时候我们可能想在算法框内书写很多没有定义的声明,如Input,Output,Procedure 1, Thread 1等等。
使用\renewcommand{\algorithmicrequire}{ \textbf{Input:}}可以强行将Require声明转换为Input:声明,但是如何在一个算法里同时使用Require,Ensure,Input,Output,Procedure 1, Thread 1呢?
解决方法
在一个算法里多次使用\renewcommand{\algorithmicrequire}{ \textbf{Input:}}命令即可。
比如
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{algorithm}[htb]
\caption{XXX algorithm}
\label{alg:XX}
\begin{algorithmic}[1] %这个1 表示每一行都显示数字
\REQUIRE % 实际显示Require
\renewcommand{\algorithmicrequire}{ \textbf{Input}}
\REQUIRE % 实际显示Input
\renewcommand{\algorithmicrequire}{ \textbf{Thread1}}
\REQUIRE % 实际显示Thread1
\end{algorithmic}
\end{algorithm}