Given the following code:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\begin{document}
\begin{center}
\begin{tikzpicture}
\node (node1) at (-6,0) [draw,fill=gray!30] {node1};
\node (node2) at (-2,-1.5) [draw] {node2};
\node (node3) at (2,-1.5) [draw] {node3};
\node (node4) at (6,-1.5) [draw] {node4};
\draw (node cs:name=node1,anchor=east) |- (8,0);
\draw (node cs:name=node4,anchor=north)[-*] |- (6,0);
\draw (node cs:name=node3,anchor=north)[-*] |- (2,0);
\draw (node cs:name=node2,anchor=north)[-*] |- (-2,0);
\end{tikzpicture}
\end{center}
\end{document}
In the resulting picture, the dots ending the lines from node2
, node3
and node4
are just below the horizontal line coming from node1
:
1) How to place the dots so that they are vertically centered over the horizontal line?
2) Is it possible to realize the same graph, with exactly the same feature, but with the trees
TikZ library, or with the forest
package? How?
Best Answer
The code below shows two different options for placing the dots on the line. The first one uses a custom arrow tip (named
Midcircle
) which is similar to the*
arrow tip you used, except that the circle is centered on the end coordinate of the path. The second option is to use anode
to make the dot, instead of an arrow tip.I also changed the coordinates you used a bit. The
node cs
coordinate system has an implicit form, so you can saynode1.east
, instead ofnode cs:name=node1,anchor=east
.And I defined the end of the vertical lines using a perpendicular coordinate:
(node2.north |- node1.east)
.