How to Draw an Equilateral Triangle in TikZ
At a glance
- 1. Choose a side length
Place two vertices on a horizontal baseline, separated by the desired side length.
- 2. Calculate the height
An equilateral triangle’s height is its side length times the square root of three divided by two.
- 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 , the altitude splits the triangle into two right triangles. Each has hypotenuse and a horizontal leg of length , so the height is
That means you can use these three vertices:
For example, if cm, the third vertex is , approximately 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 , 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 . 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 , not . 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-- cycleor 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
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.