I'm working with TikZ and am basically drawing a tree, but my needs require that the nodes be precisely positioned on the coordinate space and precisely sized. For this purpose, I've found that using the \draw
command allows me the finest control. I want, however, each node to be labeled along the edge originating from its parent (or, in the case of the root, just a label to the right).
From some other helpful answers here, I've gotten to the following MWE, which is pretty close to what I want:
\documentclass[letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[x=10mm,y=10mm,
name/.style={%
postaction={ decorate,transform shape,
decoration={ markings, mark=at position 1.0 with \node #1;}}}]
% Set styles for tree nodes
\tikzstyle{gen0} = [circle, minimum width=16pt, fill, inner sep=0pt]
\tikzstyle{gen1} = [circle, minimum width=12pt, fill, inner sep=0pt]
% ==============================
\draw[black!50] (0,0) grid (8,8);
\draw[name={[right]{nodeA}}] (3,8) node[gen0]{};
\draw[name={[above left]{nodeB}}] (3,8) -- (0,4) node[gen1]{};
\draw[name={[above left]{nodeC}}] (3,8) -- (7,2) node[gen1]{};
% ==============================
\end{tikzpicture}
\end{document}
The actual output looks like this:
My goal is to get something like this mock-up I put together in Photoshop:
In particular, I want the labels to appear a fixed distance from the edge of each node, not from the center, so they don't get covered up. I would also like the ability to choose on which side of the path the label appears, so none of them appear upsidedown.
In addition, if there is a better way to accomplish this precisely-positioned tree structure more generally with \node
and \path
commands instead of individual \draw
commands, that would be immensely helpful. My actual use-case will have a few dozen nodes among several generations with absolute coordinates to several decimal places, so I'd rather not have to keep re-listing the coordinates of the parent to draw each edge.