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

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

2 Answers 2


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.)


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]

You must log in to answer this question.

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