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'm doing a homework for algorithm class where I have to show what a particular array looks like at each step of the quick sort algorithm, in a manner similar to this image: (page from CLRS book).

array image

I would like to know how to draw an array that looks like the one in the book. In particular, I want to know how to (in order from most to least important)

  • Draw an array.

  • Put letter(s) above a node or a blank space.

  • Draw the black bars that partition the array.

  • Customize a cell with gray or light gray color.

share|improve this question
Could you show us what you've tried so far? – Seamus Feb 14 '13 at 20:32
Welcome to TeX.SE. – Peter Grill Feb 14 '13 at 20:35
@Seamus: Before I asked the question, I found the following question which shows me how to draw an array. Since I'm not familiar with using tikz, I'm unable to modify the code to include black bars, letter above a cell, or customized color (I can only modify the spacing). Note that typesetting this array is not necessary for the assignment, since I can draw it by hand. It just would be nice to know how to. – Kiet Tran Feb 14 '13 at 20:53
You can change the output. Take a look here : tex.stackexchange.com/questions/83727/… . – projetmbc Feb 14 '13 at 23:21
up vote 11 down vote accepted

Something like this perhaps

enter image description here


\@width 4\arrayrulewidth


share|improve this answer
Yes, thank you. Your code is straightforward and easy to understand, too. :) – Kiet Tran Feb 15 '13 at 3:49
@DavidCarlisle: But, but... that's not TikZ! No fair! – Jake Feb 15 '13 at 7:46

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.