需要乳胶算法和程序格式方面的帮助

需要乳胶算法和程序格式方面的帮助

我希望获得以下输出,但下面给出的代码产生了不同的输出。

这是我的代码。

\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithm}
    \caption{This is Algo. 1}
    \textbf{Input: } The .  \\
    \textbf{Output: } .
    \begin{algorithmic}[1]
    \State Here.....
    
    \end{algorithmic}
\end{algorithm}

\floatname{algorithm}{Procedure}
\begin{algorithm}
    \caption{\textproc This is procedure 1 }
    
    \textbf{Input: } The.  \\
    \textbf{Output: } .
    
\begin{algorithmic}[1]
        
    \State Here....
        
    \end{algorithmic}
\end{algorithm}
    
\begin{algorithm}
    \caption{This is procedure 2}
    \textbf{Input: } The.  \\
    \textbf{Output: } .
    
\begin{algorithmic}[1]
        
    \State Here....
        
    \end{algorithmic}
\end{algorithm}


\begin{algorithm}
    \caption{This is Algo. 2}
    \textbf{Input: } The. \\
    \textbf{Output: } . 
    
\begin{algorithmic}[1]
        
    \State Here .....
        
    \end{algorithmic}   
\end{algorithm}

\end{document}

答案1

procedure您可以通过定义一个新的计数器来完成这项工作,尝试以下代码:

\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{algorithm}
\usepackage{algpseudocode}

\newcounter{procedure}
\makeatletter
\newenvironment{procedure}[1][htb]{%
  \let\c@algorithm\c@procedure
  \renewcommand{\ALG@name}{Procedure}% Update algorithm name
  \begin{algorithm}[#1]%
  }{\end{algorithm}
}
\makeatother

\begin{document}

\begin{algorithm}
    \caption{This is Algo. 1}
    \textbf{Input: } The .  \\
    \textbf{Output: } .
    \begin{algorithmic}[1]
    \State Here.....
    
    \end{algorithmic}
\end{algorithm}

\begin{procedure}
    \caption{\textproc This is procedure 1 }
    
    \textbf{Input: } The.  \\
    \textbf{Output: } .
    
    \begin{algorithmic}[1]
        
        \State Here....
        
    \end{algorithmic}
\end{procedure}
    
\begin{procedure}
    \caption{This is procedure 2}
    \textbf{Input: } The.  \\
    \textbf{Output: } .
    
\begin{algorithmic}[1]
        
    \State Here....
        
    \end{algorithmic}
\end{procedure}

\begin{algorithm}
    \caption{This is Algo. 2}
    \textbf{Input: } The. \\
    \textbf{Output: } . 
    
\begin{algorithmic}[1]
        
    \State Here .....
        
    \end{algorithmic}   
\end{algorithm}

\end{document}

改编自这个答案

结果

相关内容