I am trying to recreate the following diagram for triangular numbers (smaller triangles within one larger triangle) using TikZ.

enter image description here

The colour is not important but white and grey is probably preferred.

I have tried to modify the code used here which produces a triangular grid but without success (I do not know how to produce more than one grid in a single figure and could not shade the triangles in the alternating pattern shown) and is the reason why I have not included any MWE.

Ideally the code would be flexible enough to choose the number of larger triangles required (6 are shown in the above figure).

  • Show what you have done already. Dec 21, 2017 at 23:40
  • Like I said, using the code in the link I can produce a single triangular grid only with no shading. I need multiple triangular grids on the same diagram that grow in size and are shaded along each column. This is what I do not know how to do.
    – omegadot
    Dec 21, 2017 at 23:45
  • So you refuse to make a minimal example? Here, have my downvote. idownvotedbecau.se/noattempt Dec 21, 2017 at 23:47
  • @Henri - that is fine. It still does not solve my problem. Like I have said, I have tried to modify code I thought would be useful to solve my problem but I simply do not know how to make it work. What I can produce is a single triangular grid with 1, 2, 3, ... columns but cannot fit more than one of these grids onto a single diagram and have no ideal how to shade them as I require.
    – omegadot
    Dec 21, 2017 at 23:53
  • 1
    @HenriMenke After downvoting please stop alienating users then. There is nothing wrong with this question and you show no attempt of engaging to answer it so leave it to people who are interested.
    – percusse
    Dec 22, 2017 at 11:25

3 Answers 3

\newcommand\triangles[2]{\def\w{#1}\foreach\n in{1,...,#2}{\path
    ([xshift=\w]current bounding box.south east)coordinate(O);
    \foreach\s[count=\c]in{\n,...,1}{\foreach\m in{1,...,\s}{

enter image description here


A small modification of Ignasi's answer on the question you refer to:

output of code


    regular polygon,
    regular polygon sides=3, 
    minimum size=2cm,
    inner sep=0pt,
    outer sep=0pt

\foreach \i [count=\row from 0, remember=\row as \lastrow (initially 0)] in {0,...,#1}{
    \foreach \j [count=\column from 0, remember=\column as \lastcolumn (initially 0)] in {0,...,\i}{
                \node[tri, anchor=corner 2](\row-0) at (\lastrow-0.corner 3) {};
                \node[tri, anchor=corner 2](\row-\column) at (\lastrow-\lastcolumn.corner 1) {};


\foreach \x in {0,...,5}
\begin{scope}[xshift=2*\x cm + \x*\x cm]
  • Thank you! It's nice to know that an answer is good enough to be recycled.
    – Ignasi
    Dec 22, 2017 at 8:27
  • \foreach options will never stop surprising me...
    – Rmano
    Dec 22, 2017 at 8:39

Almost as compact in Metapost...

enter image description here

picture trig; 
trig = image(fill origin -- right -- right rotated 60 -- cycle withcolor 1/2 white);
for k=1 upto 7:
    for j=1 upto k:
        for i=1 upto j:
            draw trig 
                 shifted (1/2(k+1)*k + 1/2(k-j) + i, sqrt(3/4)*(k-j))
                 scaled 5mm;

The trick here is that the scaled 5mm scales both the triangle picture and the amount it's shifted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.