I would like to understand how to add labels to edges and vertices and how to make an invisible vertex such that an edge can start or end in it, but the vertex itself is not visible. I'm interested only in ascending trees of this type, but i couldn't find any similar question or any specific documentation about it. I'd rather understand how to improve my (poor) code instead of changing it at all if it's possible.
CODE:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs}
\begin{document}
\begin{tikzpicture}
\graph [chain shift=(45:1), branch left, nodes={inner sep=0pt, minimum size=2.5pt, circle, fill, draw}, empty nodes]
{a -- b -- {c,d,e -- {f,g}}
};
\end{tikzpicture}
\end{document}
Any help would be appreciated.
Best Answer
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 standardlabel
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.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
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.
If you want something more like this:
then you might want to consider using the
graphdrawing
algorithms library with thetrees
graph-drawing library. This is an offline placement strategy requiring LuaTeX for compilation.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.)