Figuring out how to do stuff with the graph syntax is really just a question of reading the relevant part of the manual and/or looking at examples. If it is a tree, I would use Forest since you are not using the automatic layout algorithms anyway. However, here's an example based on your code which uses the quotes
library to label the edges and the standard label
option for the vertices. coordinate
is used to override the default node keys you've considered for a single node so that it isn't drawn.
\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{graphs,quotes}
\begin{document}
\begin{tikzpicture}
\graph [chain shift=(45:1), branch left, nodes={inner sep=0pt, minimum size=2.5pt, circle, fill, draw}, empty nodes, every edge quotes/.append style={font=\scriptsize, inner sep=0pt}]
{%
a -- ["$a$"'] b[shape=coordinate] -- {c[label=0:$w$, >"$c$"'],d[label=0:$v$],e[label=180:$u$, >"$b$"] -- {f,g}}
};
\end{tikzpicture}
\end{document}
EDIT
Note that the way the nodes are placed depends on the placement strategy in use. chain shift
shifts nodes at new levels. 45:1
means the node is place at an angle of 45 and distance of 1 from the current node. branch left
means that branches always go left.
You can
- place nodes manually (you specify exactly where to put each node);
- use an online placement strategy, like the one you've tried (you specify a strategy which takes account of the graph-so-far but not the graph-yet-to-come);
- use an offline placement strategy, which requires the advanced facilities supported by LuaTeX (you specify a strategy which takes account of the entire graph).
Sticking to the current strategy type, you can, for example, change it to grow up, branch left
:
Notice that the graph is specified in the same way - only one of the specified strategies (what to do for a new level of nodes, as opposed to a new branch) changes.
\begin{tikzpicture}
\graph [grow up, branch left, nodes={inner sep=0pt, minimum size=2.5pt, circle, fill, draw}, empty nodes, every edge quotes/.append style={font=\scriptsize, inner sep=0pt}]
{%
a -- ["$a$"'] b[shape=coordinate] -- {c[label=0:$w$, >"$c$"'],d[label=0:$v$],e[label=180:$u$, >"$b$"] -- {f,g}}
};
\end{tikzpicture}
If you want something more like this:
then you might want to consider using the graphdrawing
algorithms library with the trees
graph-drawing library. This is an offline placement strategy requiring LuaTeX for compilation.
\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage{luatex85}
\usetikzlibrary{graphs,quotes,graphdrawing}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}
\graph [tree layout, grow=up, nodes={inner sep=0pt, minimum size=2.5pt, circle, fill, draw}, empty nodes, every edge quotes/.append style={font=\scriptsize, inner sep=0pt}]
{%
a -- ["$a$"'] b -- {c[label=0:$w$, >"$c$"'],d[label=0:$v$],e[label=180:$u$, >"$b$"] -- {f,g}}
};
\end{tikzpicture}
\end{document}
If LuaTeX is not an option, for some reason, then you could always try something like Forest. (Forest can easily do this, as I mentioned above. It is probably the most powerful and flexible package for drawing trees, although it obviously does not support the other kinds of graphs the LuaTeX algorithms do.)