3
\usepackage{algorithm}
\usepackage{algorithmic}
...
\begin{algorithm}
\caption{A good name}
\begin{algorithmic}
    \REQUIRE something usefull
    \STATE $i \leftarrow 1$
\end{algorithmic}
\end{algorithm}

This works fine but there is only a line above and below the algorithm and between the caption and require. Is it possible to add an additional line between require and the first statemenent because it looks confusing especially if the requirement is long?

3

Line after Require:

To add a horizontal line after the Require you can use \hrule:

enter image description here

or a rule:

enter image description here

\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}

Alternative Solution:

A better alternative might be to use \rule and incorporate the solution form Adjust spacing of algorithm float caption, which uses \DeclareCaptionFormat from the caption package:

enter image description here

\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}
  • I want an additional line between require and the first statemenet not additional space for the caption. Thanks anyways! – Joachim Nov 27 '11 at 21:33
  • @joachim: have updated solution to add a horizontal line. – Peter Grill Nov 27 '11 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.