算法以图形表示(在图形下方包含附加标题)

算法以图形表示(在图形下方包含附加标题)

我在乳胶中有一个算法,我需要在算法下方添加一个附加标题(就像在底部的图中一样:“图 1:无论它是什么”。我尝试简单地将更改为\begin{algorithm}\begin{figure}这确实在算法下方放置了一个标题,但是,这也会改变算法的布局,我不希望发生这种情况。可以保持相同的布局,但以某种方式添加额外的标题,就像在中一样figure

这是我的代码:

\begin{algorithm}[t]
\caption{Ant Colony Algorithm}
\label{ACA}
\begin{algorithmic}
\STATE Set parameters, initialize pheromone trails
\WHILE{stopping condition not met}
\STATE construct ant paths
\STATE local search (optional)
\STATE update pheromone
\ENDWHILE
\STATE \textbf{output:} the ACO solution path
\end{algorithmic}
\end{algorithm}

答案1

浮点数algorithm采用了ruledfloat包的样式,并且这个样式是可以改变的。

\documentclass{article}

\usepackage{algorithm,algorithmic}
\makeatletter
\renewcommand\fs@ruled{%
  \def\@fs@cfont{\rmfamily}%
  \let\@fs@capt\floatc@plain%
  \def\@fs@pre{\hrule height.8pt depth0pt \kern2pt}%% or use \def\@fs@pre{} to get rid of the top rule
  \def\@fs@post{\kern2pt\hrule\relax}%% or use \def\@fs@post{} to get rid of the last rule
  \def\@fs@mid{\kern2pt\hrule\kern2pt}%% or use \def\@fs@mid{} to get rid of the middle rule
  \let\@fs@iftopcapt\iffalse}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{algorithm}[t]
\caption{Ant Colony Algorithm}
\label{ACA}
\begin{algorithmic}
\STATE Set parameters, initialize pheromone trails
\WHILE{stopping condition not met}
\STATE construct ant paths
\STATE local search (optional)
\STATE update pheromone
\ENDWHILE
\STATE \textbf{output:} the ACO solution path
\end{algorithmic}
\end{algorithm}

For reference:
\begin{table}[hb]
  \caption{Table caption}
\end{table}
\end{document}

示例输出

如果您想删除标题下方的最后一行(对我来说这样更好),请\def\@fs@post{}按照代码中所示使用。同样,如果您愿意,您可以删除任何规则。

相关内容