# How do I draw the following triangles in latex?

I would like to draw in tikz the following image:

I am not sure where to start. I thought of maybe having a node which is of triangle shape, and then positioning it in different places.

I started with this:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}

\node[fill=white,shape=circle,draw=black, minimum size=4cm] (A) at (0,4.3) {A};
\node[fill=white,shape=circle,draw=black, minimum size=3cm] (A) at (0,3.2) {A};
\node[fill=white,shape=circle,draw=black, minimum size=2cm] (A) at (0,2.1) {A};
\node[fill=white,shape=circle,draw=black, minimum size=1cm] (A) at (0,1.1) {A};

\end{tikzpicture}

\end{document}


There are several things:

1. I thought of changing the circle shapes to triangles, but when I put "triangle" instead of "circle" it doesn't work -- even though I use the shapes library.

2. I want the letter A to appear above the shape, not in the middle.

3. I want a squiggly line to connect the top of all shapes. Any squiggly line would do fine.

I would define a triangle "node" using a pic (see section 18.2 of the tikz manual, version 3.0.1a). For the MWE, we need to specify the height of the triangle and the label, so the pic needs to accept two arguments. One way to do this is to define a "triangle" pic as:

\tikzset{
pics/triangle/.style args ={#1,#2}{% pic=triangle{label, height}
code = {
\draw(0,0)node[left]{$#1$} -- ++(#2/2,-#2) -- ++(-#2,0) -- cycle;
}
}
}


This is just "normal" tikz code that gets placed whenever you "call" the pic. So, for example, with this in place you could draw a triangle of height 3 and label S with:

\begin{tikzpicture}
\pic at (0,3) {triangle={S,3}};
\end{tikzpicture}


There are several other ways to "draw" pics. For example, you can also draw this triangle with \draw(0,3)pic{triangle={S,3}};.

The easiest way to draw your "squiggly lines" is probably using a "snake decoration" -- see section 48.3 of the manual.

Putting this all together you can produce the diagram

using the code

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows.meta, decorations.pathmorphing}

\begin{document}

\tikzset{
triangle/.style = {draw=black, fill=brown!5, thick},
squiggle/.style = {decoration={snake, segment length=5mm}, decorate},
pics/triangle/.style args ={#1,#2}{% pic=triangle{label, height}
code = {
\draw[triangle] (0,0)node[left]{$#1$} -- ++(#2/2,-#2) -- ++(-#2,0) -- cycle;
}
}
}

\begin{tikzpicture}
\pic at (0,3) {triangle={S,3}};
\pic at (0,2) {triangle={P,2}};
\pic at (0,1) {triangle={P,1}};

\draw[squiggle](0,2) -- (0,3);
\draw[squiggle](0,1) -- (0,2);

\draw[-{Latex[open]}] (2,1.5) -- ++(2,0);% using arrows.meta

\pic at (6,3) {triangle={S,3}};
\pic at (6,2) {triangle={P,2}};
\pic at (6,1) {triangle={P,2}};
\pic at (6,0) {triangle={P,2}};
\pic at (6,-1.5) {triangle={P,0.5}};

\foreach \bot/\y in {-1.5/1.5, 0/1, 1/1, 2/1} {
\draw[squiggle](6,\bot) -- ++(0,\y);
}
\end{tikzpicture}

\end{document}


Partly to show how to do it, and partly to fine-tune the diagram (particularly the segment length for the snake), I have added some styling.

You called all the nodes A, which is probably not what you want, and you may use polygon instead of triangle. Putting a label on top of a node can be achieved by label=above:.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}

\node[fill=white,shape=regular polygon,regular polygon sides=3,draw=black,
minimum size=4cm,label=above:A,anchor=south] (A1) at (0,4.3) {};
\node[fill=white,shape=regular polygon,regular polygon sides=3,draw=black,
minimum size=3cm,label=above:A,anchor=south] (A2) at (0,3.2) [above]{};
\node[fill=white,shape=regular polygon,regular polygon sides=3,draw=black,
minimum size=2cm,label=above:A,anchor=south] (A3) at (0,2.1) [above]{};
\node[fill=white,shape=regular polygon,regular polygon sides=3,draw=black,
minimum size=1cm,label=above:A,anchor=south] (A4) at (0,1.1) [above]{};

\end{tikzpicture}

\end{document}


Now you can play with the coordinates. If you are always drawing the same thing just with different scales, you may consider using scope.