# Algorithm - formatting

I need some help with formatting my algorithm. What I have so far is this:

\documentclass[9pt]{sig-alternate}
\usepackage[linesnumbered,ruled]{algorithm2e}
\begin{document}
\begin{algorithm}
\SetAlgoNoLine
\KwData{The original list \textbf{R}, $N \leq n$}
\KwResult{The re-ranked list \textbf{S}}
S = <>\;
\While{ |S| < N }  {\do  {$i^{*} = argmax_{i\in R\setminus S} f_{obj}(i,S,u)$   \;
S = S $\circ i^{*}$\;
R = R $\setminus {i^{*}}$  \;
\Return{S}\;
}
\
}
\caption{The greedy strategy.}
\label{Algorithm1}
\end{algorithm}

\end{document}


I am using algorithm2e package with options linesnumbered and ruled. The desired result looks something like this:

The ruled option makes the caption appear at the top of the algorithm, but I need it to be at the bottom. Furthermore, in my document, the Return statement appears before the end statement. How can I exchange these? This is how my document looks like so far:

Thanks.

• Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document} Please do not post code as an image but as real code in the question. Oct 20, 2018 at 11:41

Here is a slightly ugly answer, but it matches your need. I added a \hrulealg macro so you can manually place some horizontal lines where you need them, and removed the ruled option. The \Return wall was placed inside the second argument of the \While, hence its former position before the end

\documentclass[9pt]{article}
\usepackage[linesnumbered]{algorithm2e}
\newcommand{\hrulealg}[0]{\vspace{1mm} \hrule \vspace{1mm}}
\begin{document}
\begin{algorithm}
\SetAlgoNoLine
\hrulealg
\KwData{The original list \textbf{R}, $N \leq n$}
\KwResult{The re-ranked list \textbf{S}}
\hrulealg
S = <>\;
\While{ |S| < N }  {\do  {$i^{*} = argmax_{i\in R\setminus S} f_{obj}(i,S,u)$   \;
S = S $\circ i^{*}$\;
R = R $\setminus {i^{*}}$  \;
}
}
\Return{S}\;
\hrulealg
\caption{The greedy strategy.}
\label{Algorithm1}
\end{algorithm}

\end{document}


There are some small differences in my output due to the use of the article class instead of sig-alternate which I do not have.