[Tex/LaTex] Horizontal line in Algorithmic Environment

algorithmsrules

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}

Best Answer

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.