LaTeX Algorithm environment

I been having trouble fine-tuning the algorithm environment in \LaTeX. For instance, I could not insert it into a figure. As I wanted to adjust the width, I tried a minipage. This works, but not to my satisfaction. For instance the vertical placement in a blob of text is a hassle, it really doesn’t want to comply. Consequently, I had to write my own. Here it is, in the essence of readable forms:

\newcounter{alg_count}

\newcommand{\alg}[4]{
\begin{table}
\centering
\begin{tabular}{l}
\toprule
\parbox{0.9\linewidth}{
\stepcounter{alg_count}
\textbf{Algorithm \arabic{alg_count}}\label{#2} {{#1}}
}\\
\midrule
\parbox{0.9\linewidth}{
\textbf{Input}: #3
}\\
\parbox{0.9\linewidth}{
{#4}
}\\
\toprule
\end{tabular}
\end{table}
}

then it is called

\alg{name}{alg:fs-alg}
{parameters}{
	\begin{enumerate}
		\item {Go to step 1.}
	\end{enumerate}
} 
Then a reference is done by […] using the bad-ass Algorithm \ref{alg:fs-alg}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s