# Tikz nodes: how to draw a decorated pentagon?

I need to draw an associahedron, i.e. a pentagon whose vertices are decorated with planar binary trees and edges decorated with planar non-binary trees. I am using TikZ with labels in forest Below is my attempt:

\begin{center}
\begin{tikzpicture}

\node[circle,draw, scale = 0.7] (A)
{\begin{forest}
for tree = {grow'=90,circle, fill, minimum width = 4pt, inner sep = 0pt, s sep = 13pt, l sep = 1ex}
[
[ [[ {},tier = top][]] [{},tier = top] ] [{}, tier = top]
]
\end{forest}};

\node[circle,draw, scale = 0.7] (B) [above right = of A] {\begin{forest}
for tree = {grow'=90,circle, fill, minimum width = 4pt, inner sep = 0pt, s sep = 13pt, l sep = 1ex}
[
[ [][] ] [ [] [] ]
]
\end{forest}};

\node[circle,draw, scale = 0.7] (C) [right = of B] {\begin{forest}
for tree = {grow'=90,circle, fill, minimum width = 4pt, inner sep = 0pt, s sep = 13pt, l sep = 1ex}
[
[{},tier = top ] [ [{},tier = top] [ [] [{},tier = top] ] ]
]
\end{forest}};

\node[circle,draw, scale = 0.7] (D) [below right = of A] {\begin{forest}
for tree = {grow'=90,circle, fill, minimum width = 4pt, inner sep = 0pt, s sep = 13pt, l sep = 1ex}
[
[[{},tier = top] [[{},tier = top][]] ] [{},tier = top]
]
\end{forest}};

\node[circle,draw, scale = 0.7] (E) [right = of D] {\begin{forest}
for tree = {grow'=90,circle, fill, minimum width = 4pt, inner sep = 0pt, s sep = 13pt, l sep = 1ex}
[
[{},tier = top] [ [[{},tier = top][{},tier = top]] [{},tier = top] ]
]
\end{forest}};

\draw[thin] (A) --node[above left,circle,draw, scale = 0.5]{\begin{forest}
for tree = {grow'=90,circle, fill, minimum width = 4pt, inner sep = 0pt, s sep = 13pt, l sep = 1ex}
[
[[{},tier = top] []]
[{},tier = top]
[{},tier = top]
]
\end{forest}} (B) --node[above,circle,draw, scale = 0.5]{\begin{forest}
for tree = {grow'=90,circle, fill, minimum width = 4pt, inner sep = 0pt, s sep = 13pt, l sep = 1ex}
[
[{},tier = top]
[{},tier = top]
[[{},tier = top] []]
]
\end{forest}}  (C) -- node[right,circle,draw, scale = 0.5]{\begin{forest}
for tree = {grow'=90,circle, fill, minimum width = 4pt, inner sep = 0pt, s sep = 13pt, l sep = 1ex}
[
[{},tier = top]
[ [{},tier = top] [] [] ]
]
\end{forest}}  (E) --node[below,circle,draw, scale = 0.5]{\begin{forest}
for tree = {grow'=90,circle, fill, minimum width = 4pt, inner sep = 0pt, s sep = 13pt, l sep = 1ex}
[
[{},tier = top]
[ [{},tier = top] [] ]
[{},tier = top]
]
\end{forest}}  (D) -- node[below left,circle,draw, scale = 0.5]{\begin{forest}
for tree = {grow'=90,circle, fill, minimum width = 4pt, inner sep = 0pt, s sep = 13pt, l sep = 1ex}
[
[[{},tier = top] [] [] ]
[{},tier = top]
]
\end{forest}}(A);
\end{tikzpicture}
\end{center}


As you can see, the resulting pentagon is ugly in several ways:

1. It is not a regular pentagon (I was positioning the nodes A-D with respect to each other in a naive way).
2. The circles at vertex nodes are different size, because the encircled label trees are different size.
3. The vertex nodes do not know that between them there edge nodes, so circles for vertex nodes and circles for edge nodes sometimes intersect.

How do I make this decorated pentagon less ugly?

• Could you provide a handmade sketch of what it should look like? Thanks Nov 13 '20 at 19:05

My answer combines two other answers, "Drawing a regular hexagon" and "Drawing tree-like symbols".

For a regular polygon, use polar coordinates (angle:radius). For a pentagon, the angle difference is 360/5=72 degrees. As the degrees start to count in the horizontal x axis, I added 36 degrees to rotate it a bit. In the TeX code below, I left the calculations explicit, e.g. 2*72+36 for the third node.

For the tree-like symbols, see the documentation in the other answer. Besides the basic commands L,I,R,l,i,r I added a few more for steeper edges (M,N,S,T,m,n,s,t). I don't know exactly how the trees are supposed to look like, but it is easy to change the size of the dots, and also to add dots at the junctions.

Final remark: TikZ is picky when nesting pictures. This becomes apparent when labeling the edges also with trees: As soon as one starts to fine-tune the position with explicit shifts, the dots in the trees start to change their position. Therefore I use saveboxes to 'freeze' the trees and then use the boxes as labels.

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{automata}

% See https://tex.stackexchange.com/a/364842 for the documentation
\makeatletter
\newcommand\RSloop{\@ifnextchar\bgroup\RSloopa\RSloopb}
\makeatother
\newcommand\RSloopa[1]{\bgroup\RSloop#1\relax\egroup\RSloop}
\newcommand\RSloopb[1]%
{\ifx\relax#1%
\else
\ifcsname RS:#1\endcsname
\csname RS:#1\endcsname
\else
\GenericError{(RS)}{RS Error: operator #1 undefined}{}{}%
\fi
\expandafter\RSloop
\fi
}
\newcommand\X{0}
\newcommand\RS[1]%
{\begin{tikzpicture}
[every node/.style=
{circle,draw,fill,minimum size=1.5pt,inner sep=0pt,outer sep=0pt},
line cap=round
]
\coordinate(\X) at (0,0);
\RSloop{#1}\relax
\end{tikzpicture}
}
\newcommand\RSdef[1]{\expandafter\def\csname RS:#1\endcsname}
\newlength\RSu
\RSu=1ex
\RSdef{i}{\draw (\X) -- +(90:\RSu) node{};}
\RSdef{l}{\draw (\X) -- +(135:\RSu) node{};}
\RSdef{m}{\draw (\X) -- +(120:\RSu) node{};}
\RSdef{n}{\draw (\X) -- +(105:\RSu) node{};}
\RSdef{r}{\draw (\X) -- +(45:\RSu) node{};}
\RSdef{s}{\draw (\X) -- +(60:\RSu) node{};}
\RSdef{t}{\draw (\X) -- +(75:\RSu) node{};}
\RSdef{I}{\draw (\X) -- +(90:\RSu) coordinate(\X I);\edef\X{\X I}}
\RSdef{L}{\draw (\X) -- +(135:\RSu) coordinate(\X L);\edef\X{\X L}}
\RSdef{M}{\draw (\X) -- +(120:\RSu) coordinate(\X L);\edef\X{\X L}}
\RSdef{N}{\draw (\X) -- +(105:\RSu) coordinate(\X L);\edef\X{\X L}}
\RSdef{R}{\draw (\X) -- +(45:\RSu) coordinate(\X R);\edef\X{\X R}}
\RSdef{S}{\draw (\X) -- +(60:\RSu) coordinate(\X R);\edef\X{\X R}}
\RSdef{T}{\draw (\X) -- +(75:\RSu) coordinate(\X R);\edef\X{\X R}}

\newsavebox\sba\savebox\sba[5mm][l]{\RS{{Mm}{Ii}{R{ir}}}}
\newsavebox\sbb\savebox\sbb[5mm][l]{\RS{{Ss}{Ii}{L{il}}}}
\newsavebox\sbc\savebox\sbc[5mm][l]{\RS{{L{lir}}{Rr}}}
\newsavebox\sbd\savebox\sbd[5mm][l]{\RS{{Ll}{Ilr}{Rr}}}
\newsavebox\sbe\savebox\sbe[5mm][l]{\RS{{Ll}{R{lir}}}}
\begin{document}
\begin{tikzpicture}[
vertex/.style={circle,draw,minimum size=8mm,inner sep=0pt},
edge/.style={circle,draw,minimum size=6mm,inner sep=0pt}
]
\newcommand\R{2cm}
\node[vertex](v0) at (0*72+36:\R) {\RS{{MMm}{S{Mm}S{ms}}}};
\node[vertex](v1) at (1*72+36:\R) {\RS{{L{li}}{R{ir}}}};
\node[vertex](v2) at (2*72+36:\R) {\RS{{SSs}{M{Ss}M{sm}}}};
\node[vertex](v3) at (3*72+36:\R) {\RS{{L{Ll}{R{lr}}}{RRr}}};
\node[vertex](v4) at (4*72+36:\R) {\RS{{R{Rr}{L{rl}}}{LLl}}};
\draw (v0) edge node[edge,above=1pt,xshift=2pt]{\usebox\sba} (v1);
\draw (v1) edge node[edge,left,yshift=4pt]{\usebox\sbb} (v2);
\draw (v2) -- node[edge,left,yshift=-4pt]{\usebox\sbc} (v3);
\draw (v3) -- node[edge,below=1pt,xshift=2pt]{\usebox\sbd} (v4);
\draw (v4) -- node[edge,right=1pt]{\usebox\sbe} (v0);
\end{tikzpicture}
\end{document}

• Great, this is just what I wanted! Thank you very much! Nov 14 '20 at 17:21
• @DashaPoliakova Just interested: Is your application related to regularity structures, as described here? Nov 14 '20 at 20:10
• No, I am writing a paper about operads and polyhedra. Nov 15 '20 at 12:06