TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to do something like this (see image below) where I can describe my algorithm in smaller steps or "phases" as this person calls them. I've used the algorithm and algorithmic package before but I can't figure out how to do these "sub-algorithms" and i cant seem to find it in any tutorial. enter image description here

share|improve this question

migrated from stackoverflow.com Aug 8 '12 at 12:56

This question came from our site for professional and enthusiast programmers.

up vote 10 down vote accepted

You can use the algpseudocode package and define a simple command to let you format the phases; a simple example:



\caption{Euclid’s algorithm}\label{euclid}
\Require something
\Ensure something
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\State \textbf{return} $b$\Comment{The gcd is b}
\Algphase{Phase 1 - Gossip piece ids}
\Require something
\State $x\gets x-1$
\Algphase{Phase 2 - Require chunks}
\Ensure something
\State $x\gets x-1$


enter image description here

share|improve this answer
Just what i was looking for, thanks! – Aleksr9 Aug 9 '12 at 11:31

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.