TikZ shapes: Triangle

  • This tutorial is the second post about TikZ shapes, or more precisely TikZ node shapes. In this post, we will learn how to create a TikZ triangle node shapechange its size, its angles, its color and access to all its anchors. Unlike the circle shape, this one requires loading shapes.geometric TikZ library

Isosceles Triangle shape in TikZ

A triangle node shape can be created by providing the option isosceles triangle to the \node command. The following line code creates a triangle node named (T) at the point with coordinates (0,0):

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}


\begin{tikzpicture}

\node[isosceles triangle,
	draw,
	fill=cyan!30,
	minimum size =3cm] (T)at (0,0){};

\end{tikzpicture}

\end{document}

TikZ Shapes Triangle LaTeX minimum size

We added draw option in order to draw the node shape, fill=cyan!30 to change the filling color of the triangle and minimum size=3cm to change its size. 

Apex angle of Isosceles triangle

Providing isosceles triangle to the node command will create an isosceles triangle with apex angle equals to 30 degrees by default. The latter can be easily changed by providing the option isosceles triangle apex angle=<value>. Here is an example:

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}


\begin{tikzpicture}

% Default apex angle 30 degrees
\node[isosceles triangle,
	draw,
	fill=teal!30,
	minimum size =2cm] (T30)at (0,0){};

% Apex angle 60 degrees
\node[isosceles triangle,
	isosceles triangle apex angle=60,
	draw,fill=teal!60,
	minimum size =2cm] (T60)at (3,0){};

% Apex angle 90 degrees
\node[isosceles triangle,
	isosceles triangle apex angle=90,
	draw,
	fill=teal!90,
	minimum size =2cm] (T90)at (6,0){};

\end{tikzpicture}

\end{document}

TikZ Shapes isosceles Triangle apex angle LaTeX

Rotate Isosceles triangle in TikZ

Rotating the Isosceles triangle can be achieved by adding rotate=<value> to the node command. Here is an example:

 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}


\begin{tikzpicture}

% 90 degrees rotation
\node[isosceles triangle,
	draw,
	rotate=90,
	fill=violet,
	minimum size =2cm] (T1)at (0,0){};


% 270 degrees rotation
\node[isosceles triangle,
	isosceles triangle apex angle=60,
	draw,
	rotate=270,
	fill=violet!50,
	minimum size =1cm] (T2)at (3,-1){};

% 90 degrees rotation
\node[isosceles triangle,
	draw,	
	rotate=90,
	fill=violet,
	rotate=90,
	minimum size =2cm] (T)at (6,0){};

\end{tikzpicture}

\end{document}

which yields the following illustration:

TikZ Shapes rotate isosceles Triangle apex angle LaTeX

Isosceles triangle anchors

The advantage of using a node triangle shape is that it defines a set of anchors that we can use them to get coordinates of the node border or to position nodes with accuracy with respect to given coordinates. By default, node center is positioned at the provided coordinates( (0,0) for previous examples).

Isosceles triangle TikZ anchors

The above triangle node is named (T) and (T.apex), (T.right corner) and (T.left corner) are the triangle vertices' coordinates. We can also use angles where (cT.180) is the coordinates of the point located at the west of the triangle node.

  • It should be noted that the triangle center anchor will be placed at the provided coordinates. Hence, adding anchor=west for example will place the node point (T.west) at the provided coordinate (0,0). Check the following example!
 \documentclass[border=0.2cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}


\begin{tikzpicture}

% Default positioning
\draw (0,0) -- (1.5,0) 
	node[draw,isosceles triangle]{};

% West anchor positioning
\draw (0,-1) -- (1.5,-1) 
	node[draw,isosceles triangle,anchor=west]{};

% Apex anchor positioning
\draw (0,-2) -- (1.5,-2) 
	node[draw,isosceles triangle,anchor=apex]{};

% Apex + rotation anchor positioning
\draw (0,-3) -- (1.5,-3) 
	node[draw,isosceles triangle,anchor=apex,rotate=180]{};

\end{tikzpicture}

\end{document}

Here is the corresponding TikZ illustration:

Position triangle using anchors TikZ LaTeX a
  • To add text, change its color, change border thickness and more customizations, I invite you to read TikZ shape: Circle post as the same applies for the TikZ triangle shape.

TikZ Example: rotated triangle

The following illustration corresponds to a set of rectangles rotated with increased size. This is achieved using only one \foreach loop. Check the code below!

TikZ Shapes Triangle LaTeX

Here is the code of the above illustration: 

 \documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}[thick,violet] 
\foreach \i in {-30,-28,...,0}{

\node[draw,
	fill=violet!10,
	isosceles triangle,
	isosceles triangle apex angle=60,
	minimum size=-2*\i mm, 
	rotate=\i,inner sep =0pt] at (0,0){};
}

\end{tikzpicture}

\end{document}

  • We've reached the end of this tutorialIf you have any questions or remarks, leave me a comment below or reach me via e-mail at admin@latexdraw.com, I will be happy to hear from you!