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.

  • 3
    Could you show us what you've tried so far?
    – Seamus
    Feb 14, 2013 at 20:32
  • 1
    Welcome to TeX.SE. Feb 14, 2013 at 20:35
  • 1
    @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, 2013 at 20:53
  • You can change the output. Take a look here : tex.stackexchange.com/questions/83727/… .
    – projetmbc
    Feb 14, 2013 at 23:21

1 Answer 1


Something like this perhaps

enter image description here


\@width 4\arrayrulewidth


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .