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.

I'd like to separate two sections in an algorithmic environment with a horizontal line, like:

-------------
Algorithm 1: MyAlgorithm
-------------
  Part 1:
  Do some stuff
-------------
  Part 2:
  Other stuff

\hline causes an error. My code so far looks like:

\begin{algorithm}
  \caption{Caption}
  \begin{algorithmic}
    \STATE algorithm here
    %I'd like to do \hline here!
    \STATE part 2 here
  \end{algorithmic}
\end{algorithm}
share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

The command \hline works only inside tables. To draw a line about the whole width you can use the command \hrulefill.

\STATE stems from the algorithms bundle, while the more advanced and recent algorithmicx package defines \State.

\documentclass{article}
\usepackage{algpseudocode}
\usepackage{algorithm}


\begin{document}
\begin{algorithm}
  \caption{Caption}
  \begin{algorithmic}
    \State algorithm here
    \\\hrulefill
    \State part 2 here
  \end{algorithmic}
\end{algorithm}
\end{document}

The result is:

enter image description here

If you want special line formating you can also use every other tool to draw a line. This is the simplest solution.

share|improve this answer
    
Thank you, looks great. –  Richante Apr 18 '12 at 21:35
add comment

Here is a mildly different approach to Marco's answer (which uses \hrulefill - a leader). The following MWE defines \algrule[<thickness>] that sets a \hrule at width \textwidth and height <thickness> (default is .4pt) vertically centered between two lines of code:

enter image description here

\documentclass{article}
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\makeatletter
\newcommand{\algrule}[1][.2pt]{\par\vskip.5\baselineskip\hrule height #1\par\vskip.5\baselineskip}
\makeatother
\begin{document}
\begin{algorithm}
  \caption{Caption}
  \begin{algorithmic}[1]
    \State First part of algorithm here
    \algrule
    \State Second part of algorithm here
    \algrule[5pt]
    \State Third part of algorithm here
  \end{algorithmic}
\end{algorithm}
\end{document}​
share|improve this answer
    
You can also use \linegoal ;-) –  Marco Daniel Apr 18 '12 at 20:49
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.