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

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?

Thanks for your answers

  • 1
    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!
    – Mensch
    Mar 19, 2015 at 11:15

1 Answer 1


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.



\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 \\
\textbf{6.} Return (some variable)


This yields the following result:

enter image description here

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





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

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

END While 
6. Return (some variable)


The result is

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.