Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have stumbled across various pseudo code packages but can't seem to find that's simple and eye-candy and practical.

What I'm looking for:

  • Visually attractive structure (eye-candy) ( easy to look at -- understandable )
  • Numbered
  • Colored (optional)
  • Title on top
  • Practical and easy to use

The one I'm using now is

\usepackage{algorithm2e} %for psuedo code
\begin{algorithm}[H] %or another one check
 \caption{How to write algorithms}
     \KwData{this text}
     \KwResult{how to write algorithm with \LaTeX2e }
     \While{not at end of this document}{
      read current\;
       go to next section\;
       current section becomes this one\;
       go back to the beginning of current section\;


which outputs

enter image description here

However, I do not really like how the code is presented here.

share|improve this question
We might be able to help you better if you state what you do not (and what you do) like about the code. “Visually attractive structure (eye-candy)” is very subjective. Some like it fancy, some like it serious. –  Qrrbrbirlbel Apr 28 '13 at 1:54
@Qrrbrbirlbel can you give a rough of example of what you mean by fancy or serious ? –  Razor Apr 28 '13 at 2:00
@Qrrbrbirlbel I updated question. –  Razor Apr 28 '13 at 2:11
I give a number of examples in Print programs with its proper syntax as discussion of the possibilities. Not sure whether it's a duplicate. –  Werner Apr 28 '13 at 3:24
I've removed the texshop tag, since it is not relevant to the question. TeXShop is an editor, and your question is about packages. –  Alan Munn Apr 28 '13 at 15:07

1 Answer 1

You may try out listings, which in the first place provides solutions to typeset program code instead of pseudo code. Allthough i think that it could work out. For instance i used it in a numerical mathematics lecture to typeset Matlab code. Since Matlab is very generic and close to Pseudo, this could fit to your problem:

\usepackage{listings} %iclude code in your document

\lstloadlanguages{Matlab} %use listings with Matlab for Pseudocode
{\lstset{language=Matlab,basicstyle=\scriptsize, keywordstyle=\color{darkblue},numbers=left,xleftmargin=.04\textwidth,#1}}

\caption{How to write algorithms}
\textbf{Data:} this text\\
\textbf{Result:} how to write algorithm with \LaTeX2e\\
while not at end of this document do
    read current;
    if understand
        go to next section;
        current section becomes this one;
        go back to the beginning of current section;

Now you just have to define a float envoirement alias of figure (packages: float, newfloat, i.e.) or use the caption package to fix that the caption of your algorithm is named "figure 1:...". With the presented solution there is only one drawback: Keywords like while,if,end,... are marked everywhere in the text, also if not needed; like in line 1 of the code. Maybe someone here knows how to work around this. In the meantime i will loke this up too.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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