# Custom pseudocode style

I want to write a custom pseudocode in latex in a similar style as the exemple below: .

I didn't manage to get what I want using existing pseudocode package, is there another way to get this kind of setting with well defined alignements?

• Please show us what you have tried so far ... It is much more easier for us to help you if we can see what you have tried ... BTW: Welcome to TeX.SE! Mar 19, 2015 at 11:15

Following are two examples of how to typeset the pseudocode.

The first example uses the cryptocode package (https://www.ctan.org/pkg/cryptocode) which gives you a lot of flexibility when writing pseudocode. The syntaxhighlighting is a bit slow to render so you might go for draft mode or do manual highlighting.

\documentclass{article}

\usepackage{cryptocode}
\begin{document}

\procedure[mode=text,keywords={Given,DO,While,END While,END DO},syntaxhighlight=auto]{Algorithm name.}{
Given: \\
$(A,B,C,D)$ -- Some parameters. \\
$n$ -- Another parameter. \\
$k$ -- Yet another pamareter. \\
$N$ -- Yet another pamareter. \\
\\
DO: \\
\textbf{1.} First step description:\\
\t for $j=1:n$\\
\t Loop definition\\
While(condition $<N$) \\
\t \textbf{2.} Second step description. \\
\vdots \\
\\
END While \\
END DO \\
\textbf{6.} Return (some variable)
}

\end{document}


This yields the following result:

Alternatively, you can use the listings package which offers a large number of options to customize how algorithms are presented. Here is a fairly simple configuration

\documentclass{article}

\usepackage{listings}

\begin{document}

\lstset{
emph={Given,DO,While,END},
emphstyle={\bfseries}
}

\begin{lstlisting}[title={\bf\underline{Algorithm name.}}]
Given:
(A,B,C,D) -- Some parameters.
n -- Another parameter.
k -- Yet another pamareter.
N -- Yet another pamareter.

DO:
1. First step description:
for j=1:n
Loop definition
While(condition <N)
2. Second step description.
...

END While
END DO
6. Return (some variable)
\end{lstlisting}

\end{document}


The result is