Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\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?

share|improve this question
    
Possible Duplicate: adjust spacing of algorithm float caption –  Peter Grill Nov 27 '11 at 21:22
add comment

1 Answer

up vote 3 down vote accepted

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}
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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