# Relative coordinates & Calc library

Attached is the code to draw a simple tree.

I wish to get the NEGF node to appear in a middle location between the "west" of the \node {Without Illumination}, and "east" of the {Geometric} node. I want this centering to happen just on the x axis while with the y axis I want it to appear "below " the {-QTBM} \node.

The issue is twofold:

1. I am trying the \x1 with let command but the compiler fails with the message:

"No shape named 0 is known"

only when I try to introduce a more complecated mathematical expression no matter I try curly brackets, paranthese, I use 0.5*, 1/2,... if I want to center between both x values.

1. If I went with a simplified version and just wanted functionality to the righmost x (NEGFr) in my coordinates, it does not appear at the exact location in the plot. The code in its current status runs with no errors but just introducing more complecated math as above breaks it.

What am I doing wrong here? & Many thanks in advance for your help N.B: Please excuse any bad coding experience here as I am completely new to these LaTeX, TikZ things

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{trees,positioning, graphs, calc}

\begin{document}

\tikz [font=\footnotesize, grow=down,
level 1/.style={sibling distance=2.6cm},
level 2/.style={sibling distance=2.5cm}, level distance=1cm]{
\node   [align =center](TOO){Theory of\\Operation } % root
child { node {Tunnelling}
child { coordinate (NEGFl) node [align=center](NI) {Without \\Illumination}}
child {node [align=center](I) {Under\\ Illumination}}
}
child { coordinate (NEGFr) node (Geo) {Geometric}
}
child { node {Hybrid}
}
;% This comma is for the parent \node DON'T REMOVE

% Now we list all the nodes down of each tree branch
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (NI.south west)(Simmons){-Simmons};
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (Simmons.south west)(Sanchez){-Sanchez};
\node[below right][inner sep = 0.4, minimum height =0.8cm] at (Sanchez.south west)(TMM){-TMM};
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (TMM.south west)(QTBM){-QTBM};
%\node[below right][inner sep = 0.4, minimum height =0.6cm, minimum width =10pt, fit = (NEGFl)(NEGFr)] at (QTBM.south west)(NEGF){-NEGF};

% Now let's list the nodes below the "With Illumination" option
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (I.south west)(PAT){-PAT};
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (PAT.south west)(Floquet){-Floquet};
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (Floquet.south west)(Mayer){-Mayer};
\path
let
\p1 = ($(NEGFr)$),
\p2 = ($(NEGFl)$)
in
node (NEGF) at (\x1,\y1) [below, draw] {{$\x1$}}; %<=== where mistakes come from
;

%Now let's put some explanatory text around
%Hint: You can use below above, right, left,... OR use anchor = east, west,...
%Single insulator models text
\node [below left, rotate=270, inner sep = 0cm, align= center, text width =1.5cm] at (Sanchez.south west)(Ss){\tiny Single barrier insulator};
%Multi insulator text
\node [below right, rotate=270, inner sep = 0cm, align= center, text width =2cm] at (Sanchez.south west)(Ms){\tiny Single \& multi barrier insulator};
%Draw dashed line to separate between single & Multi insulator models
\draw [dashed] (Ss.south east) -- ($(Sanchez.south east) + (0.5cm, 0)$);

} %This bracket closes the \tikz command
\end{document}

• Welcome to TeX.SX! Aug 20 '17 at 16:13
• it is not clear, what you like to obtain. what is purpose of \x1 calculation (which is by the way seems to be wrong)? you like know some length value? Aug 20 '17 at 17:18
• \x1 refers to point 1 which reads the coordinates of point NEGFr which in turn is identified to be the child node "geometric" in the tree structure. \\ \x2 does the exact thing to read the coordinates of the "without illumination " box to use its x coordinates.You are right I want to find the length value between x coordinates of NEGFr and NEGFl, and use it to set the width of the NEGF node. Aug 20 '17 at 18:20
• What exactly should the NEGF look like and where should it be? I gather it should be as wide as the horizontal distance between 'Without Illumination' and 'Geometric'? However, you never actually use \p2, but only the value of x from \p1.
– cfr
Aug 20 '17 at 20:59
• True this is exactly what I want, you guessed it right in your worked solution. I was using \p2 to read the coordinates of the NEGFl point. I was either to include the values of NEGFl, NEGFr into separate nodes or subtract and put the value into one node only. I was trying whichever works best for me. Aug 20 '17 at 23:27

edit: something like this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees, positioning, decorations.pathreplacing, calc}

\begin{document}
\begin{tikzpicture}[
node distance = 2mm and 0mm,
font=\footnotesize,
grow = down,
sibling distance=22mm,
level distance = 11mm,
%
B/.style = {decorate,
decoration={brace, amplitude=3pt,
raise=1mm, mirror},
thick},
every node/.append style = {align=center, anchor=north},
]
\node (TOO) {Theory of\\Operation } % root
child { node {Tunnelling}
child {node (NI) {Without \\Illumination}}
child {node (I) {Under\\ Illumination}}
}
child { coordinate (NEGFr) node (Geo) {Geometric}}
child { node {Hybrid}}
;% end of basic treee
\begin{scope}[every node/.append style={align=left}]
% Now we list all the nodes down of each tree branch
\node[below right=of NI.south west] (Simmons)   {- Simmons\\[1ex]
- Sanchez};
\node[below right=of Simmons.south west] (TMM)  {- TMM\\[1ex]
- QTBM};
\node[below right=of I.south west] (PAT)        {- PAT\\[1ex]
- Floquet};
\node[below right=of PAT.south west] (Mayer)    {- Mayer};
\end{scope}
% NEGF node
\path (TMM.south west) -- coordinate (aux) (TMM.south -| Geo.east);
\path   let \p1 = ($(TMM.west) - (TMM -| Geo.east)$),
\n1 = {veclen(\x1,\y1)} in
node (NEGF) [draw, minimum width=\n1, below=of aux] {- NEGF};
% explanatory text
\draw[B]    (Simmons.north west) --
node[below=2mm,font=\tiny, sloped] {Single\\ barrier\\ insulator}
(Simmons.south west);
\draw[B]    (TMM.north west) --
node[below=2mm,font=\tiny, sloped] {Single \& \\ multi barrier\\ insulator}
(TMM.west |- NEGF.south);
\end{tikzpicture}
\end{document}

• Cheers Zarko, Very close with just one additon; I wish to add another node whose name is {-NEGF}, and is meant to horizontally span the tree such that it starts from the left side of the nodes below {-QTBM} and extends to below the right side of the {Geometric}. Of course, it should be the lowest item (i.e. comes below the {-QTBM} node. For that reason I used the \p & let comands to extract the x ccordinates of both boxes, start drawing the node from the middle x-space between them, but should be located with the y of the lowest node (i.e. (QTBM) one) Aug 20 '17 at 21:40
• @Mazen, thank you for comment. i correct my mwe accordingly Aug 21 '17 at 1:29
• Cheers Zarko now that works! I have altered this bit in my code just a little but all in all this is great! I will post the working code AW. Aug 21 '17 at 10:16

Something like this?

I used Forest because it makes doing things with trees much easier, generally. I used fit to create the spanning node.

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{positioning,fit,calc}
\begin{document}
\begin{forest}
for tree={%
align=center,
font=\footnotesize,
},
before typesetting nodes={%
where={ > Ow+P {n children} {isodd(#1)} }{%
calign=child edge,
if n children=1{%
parent anchor=south west,
for children={%
no edge,
align=left,
content/.wrap value={\textbullet{} #1},
child anchor=north west,
anchor=north west,
before computing xy={l'=1.75\baselineskip},
},
}{%
calign child/.process={ Ow+n {n children} {(#1+1)/2} },
},
}{},
}
[Theory of\\Operation, name=to % names are optional - needed only if you want to refer to nodes by name later
[Tunnelling, name=t
[Without\\Illumination, name=wi
[Simmons, name=si
[Sanchez, name=sa
[TQM, name=tq
[QTBM, name=qtbm]
]
]
]
]
[Under\\Illumination, name=i
[PAT, name=p
[Floquet, name=f
[Mayer, name=m]
]
]
]
]
[Geometric, name=g]
[Hybrid, name=h]
]
\path (current bounding box.south west) coordinate (b) -- (b -| g.east) node (n) [midway, below, font=\footnotesize] {\textbullet{} NEGF};
\node [draw, inner sep=0pt, fit=(n) (b) (b -| g.east)] {};
\begin{scope}[every node/.append style={font=\tiny, rotate=270, inner sep =0cm, align=center}]
\node (sb) [anchor=north east] at (sa.south west) {Single barrier\\insulator};
\node (sbm) [anchor=north west] at (tq.north west) {Single \& multi\\barrier insulator};
\end{scope}
\draw [densely dashed] (current bounding box.west |- {$(sa.south)!1/2!(tq.north)$}) coordinate (a) -- (wi.east |- a);
\end{forest}
\end{document}

• Many thanks cfr, The diagram is what I want. However, this is too advanced for the level of work im doing. I wish also to extend over the already available code becuase this is not the final form and there may be some alterations, and so I wish to have a scalable code I can understand. BTW: I have read Ow+P & Ow+n are arguments processors but wasn't able to understand what they do exactly. Aug 20 '17 at 23:20
• @Mazen Best use Zarko's code, then. I added this as an alternative since you already have an answer which modifies your existing code. Forest is great, but it isn't always the best tool, especially given an existing document which relies on an alternative. Yes, they are argument processors. Ow+P means the first argument is the name of an option, the next argument does something with the value of that option and processes it with pgfmath (e.g. checking if odd). Ow+n is the same, but the processing is done using TeX manipulation of number expressions (e.g. summation), which is faster.
– cfr
Aug 20 '17 at 23:56
• @Mazen Note that the code I gave for the node you wanted to add doesn't depend on Forest. You can use it with Zarko's code for the rest. It is just TikZ code at that point. Just use it after drawing the tree but before adding the annotations at the left side.
– cfr
Aug 20 '17 at 23:58

Following is the working code. Altered a tiny bit of that of @Zarko. A very enlighting note is gievn by @cfr. So many thanks to both of you.

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{trees,positioning, graphs, calc}

\begin{document}

\tikz [font=\footnotesize, grow=down,
level 1/.style={sibling distance=2.6cm},
level 2/.style={sibling distance=2.5cm}, level distance=1cm]{
\node   [align =center](TOO){Theory of\\Operation } % root
child { node {Tunnelling}
child { coordinate (NEGFl) node [align=center](NI) {Without \\Illumination}}
child {node [align=center](I) {Under\\ Illumination}}
}
child { coordinate (NEGFr) node (Geo) {Geometric}
}
child { node {Hybrid}
}
;% This comma is for the parent \node DON'T REMOVE

% Now we list all the nodes down of each tree branch
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (NI.south west)(Simmons){-Simmons};
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (Simmons.south west)(Sanchez){-Sanchez};
\node[below right][inner sep = 0.4, minimum height =0.8cm] at (Sanchez.south west)(TMM){-TMM};
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (TMM.south west)(QTBM){-QTBM};
%\node[below right][inner sep = 0.4, minimum height =0.6cm, minimum width =10pt, fit = (NEGFl)(NEGFr)] at (QTBM.south west)(NEGF){-NEGF};

% Now let's list the nodes below the "With Illumination" option
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (I.south west)(PAT){-PAT};
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (PAT.south west)(Floquet){-Floquet};
\node[below right][inner sep = 0.4, minimum height =0.6cm] at (Floquet.south west)(Mayer){-Mayer};

\draw (QTBM.south west) -- coordinate (aux) (QTBM.south -| Geo.east);
\path   let
\p1=($(QTBM.west) - (QTBM -| Geo.east)$),
\n1= {veclen(\x1, \y1)}
in
node (NEGF) [below right, draw, minimum width=\n1 ] at (QTBM.south west) {-NEGF}
;

%Now let's put some explanatory text around
%Hint: You can use below above, right, left,... OR use anchor = east, west,...
%Single insulator models text
\node [below left, rotate=270, inner sep = 0cm, align= center, text width =1.5cm] at (Sanchez.south west)(Ss){\tiny Single barrier insulator};
%Multi insulator text
\node [below right, rotate=270, inner sep = 0cm, align= center, text width =2cm] at (Sanchez.south west)(Ms){\tiny Single \& multi barrier insulator};
%Draw dashed line to separate between single & Multi insulator models
\draw [dashed] (Ss.south east) -- ($(Sanchez.south east) + (0.5cm, 0)$);

} %This bracket closes the \tikz command
\end{document}