Is there an easy way to draw a triangular grid in TikZ, like this?

  • Just a pointer. Sorry for not offering real code. I'd draw it just like there were no grid. Use foreach to draw the three sets of lines. – Leo Liu Aug 18 '10 at 12:54

Like Leo said: use \foreach and some math:


    \foreach \row in {0, 1, ...,\rows} {
        \draw ($\row*(0.5, {0.5*sqrt(3)})$) -- ($(\rows,0)+\row*(-0.5, {0.5*sqrt(3)})$);
        \draw ($\row*(1, 0)$) -- ($(\rows/2,{\rows/2*sqrt(3)})+\row*(0.5,{-0.5*sqrt(3)})$);
        \draw ($\row*(1, 0)$) -- ($(0,0)+\row*(0.5,{0.5*sqrt(3)})$);
| improve this answer | |
  • 7
    If I'm not mistaken, for an equilateral triangle, those should all be sqrt(3), not sqrt(2). (Though maybe you didn't want an equilateral one, in which case, ignore me.) – Sophie Alpert Aug 19 '10 at 4:28
  • 11
    Well, that is rather embarrassing. Don't tell anyone! ;) – Caramdir Aug 19 '10 at 8:39

A funny solution (have you ever used lindenmayersystems library?):

  \pgfdeclarelindenmayersystem{triangular grid}{\rule{F->F-F+++F--F}}
  l-system={triangular grid,step=1cm,
  lindenmayer system -- cycle;
| improve this answer | |
  • Wow, that's pretty clever! – Jake Jun 26 '12 at 0:25
  • 2
    Great example of lateral thinking -- congratulations! – Brent.Longborough Jun 26 '12 at 10:30
  • 7
    The question is not "have you ever used lindenmayersystems library", but "did you even know about it's existence". Very nice! – Tom Bombadil Jun 26 '12 at 10:42
  • 1
    @TomBombadil How to use TikZ without reading the manual? How to read pgfmanual without reading all chapters? ;-) – Paul Gaborit Jun 26 '12 at 22:10

A slightly different solution using a matrix transformation and clipping:



    \path[clip,preaction = {draw=black}] (\rows,0) -- (0,0) -- (0,\rows) -- cycle;
    \draw (0,0) grid (\rows,\rows);
    \foreach \x in {1,2,...,\rows} {
        \draw (0,\x) -- (\x,0);
| improve this answer | |
  • Very beautiful! – Paul Gaborit Jun 26 '12 at 0:28
  • 1
    Nice. (nitpick: the last (\rows,0) can be cycle :P) – percusse Jun 26 '12 at 9:44
  • Very nice (and very convenient when one needs to draw something on triangular grid). – Grigory M Dec 8 '14 at 15:43

You could abuse the pgfplots tenary plot feature for this. On the plus side it allows you to easily plot data in that grid.

    major tick length=0,
    minor tick length=0,
    minor tick num=2,
    every axis grid/.style={},

enter image description here

| improve this answer | |

Next code defines command \grid which draws a triangular grid made with triangular nodes. \grid's parameter is the number of rows. minimum size in tri/.style is the diameter of triangle's circumscribed circle.

With nodes instead of just lines, it's easier to use the grid as base for nice TiKZ drawings.


\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=north](\row-0) at (\lastrow-0.corner 2) {\row-0};
                \node[tri, anchor=north](\row-\column) at (\lastrow-\lastcolumn.corner 3) {\row-\column};

\begin{tikzpicture}[tri/.style={draw=gray, regular polygon, regular polygon sides=3, 
                            minimum size=2cm, inner sep=0pt, outer sep=0pt}]


\begin{scope}[draw=yellow!30!black, very thick, fill=yellow!80!black]
\filldraw[fill opacity=.7] (5-2.corner 2)--(4-0.corner 1)--(4-1.corner 1)--
         (2-1.corner 1)--(3-2.corner 3)--(4-4.corner 1)--(5-4.corner 2)--cycle;

\draw (4-1.corner 1) -- (4-3.corner 1) (4-2.corner 1)--(2-1.corner 1);



enter image description here

| improve this answer | |
  • 1
    Perhaps one should call it \trid instead of \grid ;) – Carel Aug 25 '15 at 17:33

A MetaPost version, as a complement. It is based on a recursion inspired by Paul Gaborit's use of the lindenmayersystems library. I borrowed much code from my answer to a related question.

Note that at each recursion only the midpoints triangle is drawn, in order not to draw the same segments more than once (which would result in a much thicker rendering of these segments).The main, biggest triangle being drawn only once, before the recursion takes place.

To be run with LuaLaTeX.

vardef triangular_grid(expr A, B, C, n) = % Recursive macro à la MetaPost
   if n>0:
      save midAC, midBC, midAB; pair midAC, midBC, midAB;
      midAC = .5[A, C]; midBC = .5[B, C]; midAB = .5[A, B];
      triangular_grid(A, midAB, midAC, n-1);
      triangular_grid(midAB, B, midBC, n-1);
      triangular_grid(midBC, midAC, midAB, n-1);
      triangular_grid(midAC, midBC, C, n-1);
      draw midAB--midAC--midBC--cycle;
   u := 14cm; pair A, B, C; A = origin; B =  (u, 0); C = u*dir 60;
   draw A--B--C--cycle; 
   triangular_grid(A, B, C, 4);

enter image description here

| improve this answer | |

At risk of starting a "code golf" war, but in the spirit of "TIMTOWTDI",


If you want to avoid double-drawn grid lines, then line 4 is



  • No point including a picture here, as it looks like those above.
  • Yes, this is similar to answer contributed by @finite
| improve this answer | |

Probably not the most elegant, but slightly simplified (from my perspective) variant of Caramdir's answer.




        \tikzstyle{every node}=[draw,thin]

        \foreach \a in {1,...,\gridsize}{
            \draw[dotted] (0, 0) -- (\a, 0) -- ({cos(60)*\a}, {sin(60)*\a}) -- cycle;
            \draw[dashed] ({\gridsize-\a}, 0) -- (\gridsize, 0) -- ({\gridsize-cos(60)*(\a)}, {sin(60)*(\a)}) -- cycle;
            \draw[red] ({cos(60)*(\gridsize-\a)}, {sin(60)*(\gridsize-\a)}) -- ({(\gridsize/2)+cos(60)*\a}, {sin(60)*(\gridsize-\a)}) -- ({cos(60)*\gridsize}, {sin(60)*\gridsize}) -- cycle;

\caption{Triangular grid}


Charles Staats contributed to this solution in Drawing scaled triangles with their bottom left corner at the same coordinates in TikZ as I became fixated on using polygons.

| improve this answer | |

This is a full-page triangular grid I created recently. My approach was to slant vertical lines in both directions.



\pgfmathsetmacro{\height}{0.5 * \rows * tan(60)}

    \clip       (0, 0) rectangle (\cols, \height);
    \draw[gray] (0, 0) rectangle (\cols, \height);

    \pgfmathsetmacro{\from}{-2 *\cols}
    \pgfmathsetmacro{\to}{2 * \cols}
    \foreach\i in {\from, ..., \to} {
        \draw[gray, dotted, xslant=\slant]  (\i, 0) -- (\i, \height);
        \draw[gray, dotted, xslant=-\slant] (\i, 0) -- (\i, \height);

    \foreach\j in {0, ..., \rows} {
        \pgfmathsetmacro{\y}{0.5 * \j * tan(60)}
        \draw[gray, dotted] (0, \y) -- (\cols, \y);


Full-page triangular grid

| improve this answer | |

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.