Tx · LaTeX & TikZ

How to Draw an Equilateral Triangle in TikZ

Published By the 9to5Science editorial team

At a glance

  1. 1. Choose a side length

    Place two vertices on a horizontal baseline, separated by the desired side length.

  2. 2. Calculate the height

    An equilateral triangle’s height is its side length times the square root of three divided by two.

  3. 3. Connect the vertices

    Draw the three edges and use cycle to close the path.

The simplest way to draw an equilateral triangle in TikZ is to put one side horizontally and calculate the height of the third vertex. This gives you exact geometry and makes it easy to choose the triangle’s size or add labels.

Set the vertices using the height

For side length ss, the altitude splits the triangle into two right triangles. Each has hypotenuse ss and a horizontal leg of length s/2s/2, so the height is

h=s2−(s/2)2=32s.h=\sqrt{s^2-(s/2)^2}=\frac{\sqrt{3}}{2}s.

That means you can use these three vertices:

A=(0,0),B=(s,0),C=(s/2,3s/2).A=(0,0),\qquad B=(s,0),\qquad C=(s/2,\sqrt{3}s/2).

For example, if s=4s=4 cm, the third vertex is (2,23)(2,2\sqrt{3}), approximately (2,3.464)(2,3.464) cm.

Complete TikZ example

This file draws a triangle with 4 cm sides and labels the vertices. The standalone document class crops the output to the drawing; the tikz package provides the tikzpicture environment.

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[x=1cm,y=1cm]
  \coordinate (A) at (0,0);
  \coordinate (B) at (4,0);
  \coordinate (C) at (2,{2*sqrt(3)});

  \draw[thick] (A) -- (B) -- (C) -- cycle;

  \node[below left]  at (A) {$A$};
  \node[below right] at (B) {$B$};
  \node[above]       at (C) {$C$};
\end{tikzpicture}
\end{document}

The explicit x=1cm,y=1cm setting means each coordinate unit corresponds to one centimeter. TikZ evaluates {2*sqrt(3)} as a coordinate expression, giving the altitude for a side of length 4. The cycle command closes the outline by drawing from C back to A.

To change the size, change the coordinates consistently. For a different side length ss, use (0,0), (s,0), and (s/2,{s*sqrt(3)/2}), replacing each s with its numerical value. For example, a side length of 6 uses (0,0), (6,0), and (3,{3*sqrt(3)}).

Compact alternative with polar coordinates

TikZ also accepts polar coordinates in the form (angle:radius). Three points on a circle, separated by 120 degrees, form an equilateral triangle:

\begin{tikzpicture}
  \draw[thick] (0:2) -- (120:2) -- (240:2) -- cycle;
\end{tikzpicture}

Here, 2 is the distance from the origin to each vertex, not the side length. It is the circumradius, so the triangle’s side length is 232\sqrt{3}. Use the height-based construction when you want to specify the side length directly; use polar coordinates when a centered, symmetric triangle is convenient.

Common mistakes

  • Using the side length as the height. The height is s3/2s\sqrt{3}/2, not ss. For a 4-unit side, a height of 4 would make a taller, non-equilateral triangle.
  • Forgetting to close the outline. The two segments in (A) -- (B) -- (C) do not automatically form a closed shape; add -- cycle or draw the last edge explicitly.
  • Mixing units. If you set x=1cm,y=1cm, the coordinates above are in centimeters. If you change the coordinate scales, the printed dimensions change too.
  • Confusing radius and side length. In the polar version, the value after the colon is the distance from the origin to a vertex. It is not the length of an edge.

For a filled triangle, replace \draw[thick] with \filldraw[thick,fill=blue!15]. TikZ fills the area enclosed by the same closed path.

References

  1. TikZ & PGF Manual

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.