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

How can I generate a step-pyramid in LaTeX?

I'm guessing I would use a graph module to centre chart bars...

I want to be able to select the length of each "row" of the pyramid, and show that number next to it, like so: Mockup

Thanks for all suggestions

share|improve this question
Those bars don't look centred. Should we assume that they are? – huon May 4 '12 at 7:29
Yes, rocked this up in paint. Also assume that it isn't to scale! – A T May 4 '12 at 7:38
@AT Shouldn't the 20 be 21? – Yiannis Lazarides May 4 '12 at 8:23
-_- < "Not to scale" – A T May 4 '12 at 11:23
up vote 12 down vote accepted

I suggest you use TikZ and a \foreach loop





        \foreach \b [count=\n] in {#1} {
            \draw [barborder,fill=barcolor]
                (-0.5*\b,{(\n-1)*\barheight}) rectangle (0.5*\b,\n*\barheight);
            \node at (-0.5*\b,\n*\barheight-0.5*\barheight) [left] {\b};




  • Us it with \pyramid{<values>} separate the values with commas , and sort the descending.

  • Set the colors barcolor and barborder with xcolor.

  • Change x=0.25cm to scale the image vertically.

  • Change \newcommand{\barheight}{0.5cm} to set the height of the bars.

  • You may want to add a font setting in the node like this

    \node at (...) [left,font=\small] {\b};
  • It is also possible to align the numbers above each other.

        \foreach \b [count=\n] in {#1} {
                    % Store the first value in the list
            \draw [barborder,fill=barcolor]
                (-0.5*\b,{(\n-1)*\barheight}) rectangle (0.5*\b,\n*\barheight);
            \node at (-0.5*\firstbarwidth,\n*\barheight-0.5*\barheight) [left] {\b};

    result 2

    (I changed the macro name to \Pyramid, with an uppercase P, so you can compare them in one document.)

share|improve this answer
Awesome, thanks – A T May 4 '12 at 11:23

Minimalistic non-TikZ solution, with a bit of color and shade. Adjust to suit taste.

enter image description here

\fbox{\thectra}\colorbox{gray}{\color{olive}\rule{\the\rwidth}{30pt} }\\[-1.0pt]
share|improve this answer
Indeed a nice one! – percusse May 4 '12 at 9:23
@percusse Thanks! With a stick on top it will look like the Tower of Hanoi:) – Yiannis Lazarides May 4 '12 at 9:34
Actually I was expecting yet another Alan Mcdonald appearing somewhere in the corner of my eye :) – percusse May 4 '12 at 9:36

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.