\usepackage{algorithm}
\usepackage{algorithmic}
...
\begin{algorithm}
\caption{A good name}
\begin{algorithmic}
\REQUIRE something usefull
\STATE $i \leftarrow 1$
\end{algorithmic}
\end{algorithm}
运行正常,但算法上方和下方以及标题和要求之间只有一行。是否可以在要求和第一个语句之间添加额外的一行,因为它看起来很混乱,特别是当要求很长时?
答案1
下一行Require
:
要在之后添加水平线,Require
可以使用\hrule
:
或rule
:
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}
\caption{A good name}
\begin{algorithmic}
\REQUIRE something useful \vspace{4pt}\hrule\vspace{5pt}
\STATE $i \leftarrow 1$
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{A good name}
\begin{algorithmic}
\REQUIRE something useful \vspace{4pt}\par\rule{\linewidth}{0.5pt}\vspace{5pt}
\STATE $i \leftarrow 1$
\end{algorithmic}
\end{algorithm}
\end{document}
替代解决方案:
更好的选择可能是使用\rule
并结合解决方案形式调整算法浮动标题的间距,它使用\DeclareCaptionFormat
来自caption
包的:
\documentclass{article}
\usepackage{caption}
\usepackage{algorithm}
\usepackage{algorithmic}
\DeclareCaptionFormat{algorithm}{\vspace{0ex}{%
\parbox[c][1.75em][c]{\textwidth}{#1#2#3}}\par\rule{\linewidth}{0.5pt}}
\captionsetup[algorithm]{format=algorithm}
\begin{document}
\begin{algorithm}
\caption{A good name}
\begin{algorithmic}
\REQUIRE something usefull \vspace{4pt}\par\rule{\linewidth}{0.5pt}\vspace{5pt}
\STATE $i \leftarrow 1$
\end{algorithmic}
\end{algorithm}
\end{document}