# How to reformat Algorithm in memoir document class?

I'm trying to typeset algorithms in the memoir class. I'm using the algorithmic package with a custom environment as this was the only way I could get the list of algorithm to display correctly in the table of content, and the algorithm to be listed correctly in the list algorithms. As shown in the following images,

Currently the algorithm is displayed as follows,

How to I reformat the algorithms environment to look more like the following?

I don’t need the exact formatting, just something more professional. I would ideally like line numbering, the vertical lines, the horizontal lines, and some form of left and right indentation that is less than the text width. My current code is,

\documentclass[]{memoir}
\usepackage[utf8x]{inputenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{algorithmic}

\newcommand{\algorithmname}{Algorithm}
\newcommand{\listalgorithmname}{List of Algorithms} \newlistof{listofalgorithms}{loa}{\listalgorithmname}
\newfloat{algorithm}{loa}{\algorithmname}
\newfixedcaption{\falgcaption}{algorithm}
\newlistentry{algorithm}{loa}{0}

\begin{document}
\tableofcontents
\newpage
\listoffigures
\listoftables
\listofalgorithms

\newpage
\chapter{Example Chapter}
\section{Example Section}

\begin{algorithm}[htbp]
\hrulefill
\caption{An Algorithm Template}
\label{alg1}
\hrulefill
\begin{algorithmic}
\REQUIRE $n \geq 0$
\ENSURE $y = x^n$
\STATE $y \leftarrow 1$
\STATE $X \leftarrow x$
\STATE $N \leftarrow n$
\WHILE{$N \neq 0$}
\IF{$N$ is even}
\STATE $X \leftarrow X \times X$
\STATE $N \leftarrow N / 2$
\ELSE[$N$ is odd]
\STATE $y \leftarrow y \times X$
\STATE $N \leftarrow N - 1$
\ENDIF
\ENDWHILE
\end{algorithmic}
\hrulefill
\end{algorithm}
\end{document}

-

You can load the float package after having defined the new float with memoir macros:

\newcommand{\algorithmname}{Algorithm}
\newcommand{\listalgorithmname}{List of Algorithms}
\newlistof{listofalgorithms}{loa}{\listalgorithmname}
\newfloat{algorithm}{loa}{\algorithmname}
\newfixedcaption{\falgcaption}{algorithm}
\newlistentry{algorithm}{loa}{0}

\usepackage{float}
\floatstyle{ruled}
\restylefloat{algorithm}


Then remove the \hrulefill commands and you'll get the "traditional" format.

-

I'm very happy with algorithm2e and memoir. But I had to add the following in the body of the text for the TOC (the text is is Spanish, that is why I had to reset the names, babel doesn't handle it, the spacing is to make the list of algorithms use the same spacing as the one adjusted for the other lists of...):

%%%
%%% For algorithm2e
%%%

\SetAlgorithmName{Algoritmo}{Algoritmo}{Índice de algoritmos}
\newlistof{listofalgorithms}{loa}{\listalgorithmcfname}
\makeatletter
\renewcommand{\l@algocf}{\@dottedtocline{1}{1em}{3.5em}}
\makeatother

-
I couldn't get this to work. If you could maybe provide a full example instead. –  entropy Feb 20 '13 at 9:43