Possibly this is closer to what you want. Certainly the picture produced is what you ordered:
The drawing of the "children" is done using essentially what you had. The only difference is that I have given node names to some of the children. I have drawn the a, ab, abc "by hand" inside a \foreach
loop inside the tikzpicture
environment and given them names to help draw their L
and R
labels.
The fun and games comes in actually drawing the L
and R
labels down the left and right hand sides. This is done using a \foreach
loop over all of the node names that should be marked with an L
or with an R
. In your example these could be combined into one loop but I assumed that there would be some rows with only one label so I used two loops. To add or remove these labels you just add or remove a node in the corresponding row from the \foreach
loop.
The point is that these \foreach
loops are the only place where you need to specify the rows that should be given left and right markings.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[sibling distance=5cm,
edge from parent/.style={draw,blue!80,thick,->}]
\node(A){Prova}
child {node {Second line - left} }
child {node (B) {Second line - right}
child {node (C) { Third line - left}}
child {node {Third line }}
};
% place the text below the kids
\foreach \txt/\Y in {a/-4,ab/-5,abc/-6} {
%\txt=label+anchor name, \Y=y-coord, \x1=x-coord of (B)
\path let \p1 = (B) in node (\txt) at (\x1,\Y){\txt};
}
% loop over the "left" nodes
\foreach \Node in {A,B,C,a,ab,abc} {%\y1=y-coord of the node
\path let \p1=($ (\Node) $) in node at (-5,\y1){L};
}
% loop over the "right" nodes
\foreach \Node in {A,B,C,a,ab,abc} {%\y1=y-coord of the node
\path let \p1=($ (\Node) $) in node at (7,\y1){R};
}
\end{tikzpicture}
\end{document}
To loop over the node names I use the calc package to evaluate the nodes. This seems a little OTT to me but I couldn't find a better way of doing this, and I remembered seeing something like this somewhere else. The trick of using \let
to get the (x,y)-coordinates of the nodes comes from
tikz-node-at-same-x-coordinate-as-another-node-but-specified-y-coordinate.