# Reproduce neat Algorithm Style

I've seen this nice algorithm sytle in Stachurski (2009), "Economic Dynamics", p.74.

• Does someone know what package, environment or settings he used?

• Use package algorith2e – Yiannis Lazarides Jun 26 '15 at 12:55
• Do you mean algorithm2e? – Paul Stiverson Jun 26 '15 at 13:28
• @PaulStiverson Yes sure, that was a typo. Just watch out for hyperref problems with it. – Yiannis Lazarides Jun 26 '15 at 17:06

Algorithm2e is the package to use:

\documentclass{amsart}

\usepackage[ruled]{algorithm2e}
\usepackage{mathpazo}
\SetAlgoInsideSkip{medskip}

\begin{document}

\begin{algorithm}
%\BlankLine
\DontPrintSemicolon
\For{i in 1 to n}{
draw $X\sim\psi$\;
\For{j in 1 to t}{
draw $X\sim p(X,dy)$
}
set $X^i_t=X$\;
}
\Return{$(1/n)\sum^n_{i=1}\mathbb{1}\{X^i_t=y\}$}
%\BlankLine
\caption{Approximate marginal distribution}
\end{algorithm}
\end{document}


Later: I noticed that the original sample had some additional space at the beginning and end of the algorithm. At first, as you can see, I tried \BlankLine, but that seemed like a kluge, so I used \SetAlgoInsideSkip{medskip} so as to be the default.

You can use the algorithm2e package. The documentation is available from CTAN. Here is a quick workup of the algorithm, but note that there are many options you can tweak to get the appearance just as you want it.

\documentclass{article}
\usepackage{algorithm2e, bbold}

\begin{document}
\begin{algorithm}
\For{i in 1 to n} {
draw $X \sim \psi$\;
\For{j in 1 to t}{
draw $X \sim p(X,dy)$\;
}
set $X_t^i = X$\;
}
\Return  $(1/n) \sum_{i=1}^n \mathbb{1} \left\{X_t^i = y\right\}$
\end{algorithm}
\end{document}


The above LaTeX gives the following output: