I am using the trees tikzlibrary combined with some pgfmath commands to draw the ternary tree below:
To each vertex u_i, a certain v_i is associated. So far, all of these v_i's are labelled with v_1, but I would actually like the numbering to correspond to the u_i's, so that v_1 is adjacent to u_1, v_2 is adjacent to u_2, and so on.
Code:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\pagestyle{empty}
\def\d{3} %degree
\newlength{\leveldist} %level distance
\centering
\begin{tikzpicture}[grow cyclic,circle,sibling angle=360/\d,draw]
\setlength{\leveldist}{10mm};
\tikzstyle{level 1}=[level distance=1.5\leveldist]
\tikzstyle{level 2}=[level distance=\leveldist,sibling angle=60]
\tikzstyle{level 3}=[level distance=\leveldist,sibling angle=40]
\tikzstyle{every node}=[inner sep=0mm,minimum size=1mm,draw]
\node (Ac) {$u$} child foreach \A in {1,...,\d}
{ node (A\A) {} child foreach \B in {2,...,\d}
{ node (A\A-\B) {$u_{\pgfmathparse{(\A-1)2+\B-1}\pgfmathprintnumber{\pgfmathresult}}$} child foreach \C in {2,...,\d}
{ node (A\A-\B-\C) {\pgfmathparse{ifthenelse(array({0,1,1,1,0,1},(\A-1)2+\B-2)==\C-2,"$v_1$","")} \pgfmathresult} }
}
};
\end{tikzpicture}
\end{document}
Here, using "$v_{\pgfmathparse{(\A-1)*2+\B-1}\pgfmathprintnumber{\pgfmathresult}}$"
instead of "$v_1$" to label the v_i (as it worked for the u_i in the line above) results in the compilation not terminating, probably because of the nested use of the two \pgfmathparse commands.
An alternative approach could be to introduce some variable to count the index instead of doing the computation in situ, but I was not able to make this work inside this structure.


minimaldocumentclass. It is way too minimal for most purposes. – Henri Menke Oct 29 '21 at 12:10article(in my file) now. The problem persists, however. – user631620 Oct 29 '21 at 12:17\tikzstyleanymore, but instead use\tikzset{<key-name>/.style={<stuff>}}(this will most likely not fix your problem though). – Skillmon Oct 29 '21 at 19:08