# Tree node alignment wrong

I am having a mental block and I hope someone can help. I am trying to draw the following tree and have two problems:

1. The subtree that is rooted at the left-most "doc" should be rooted at node &o2. Don't know why it is coming up this way.
2. The edges should be directed.

Here is my MWE:

\documentclass[margin=1mm,xcolor=pdftex,dvipsnames]{standalone}

\usepackage{tikz}

\tikzset{every picture/.style={/utils/exec={\sffamily}},>=latex,align=center,font={\fontsize{10pt}{12}\selectfont}}

\begin{document}

\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=3.5cm},
level 2/.style={sibling distance=2cm},
tree node/.style={circle,draw,inner sep=1pt,minimum width=0.5cm},
every child node/.style={tree node}]

\node[circle,draw] {\&o1}
child {node {\&o2} edge from parent node[midway] {doc}
child {node {\&o3} edge from parent node[midway] {authors}}
child {node {\&o6} edge from parent node[midway] {title}}
}
child {node {\&o22} edge from parent node[midway] {doc}}
child {node {\&o34} edge from parent node[midway] {doc}}
;
\end{tikzpicture}

\end{document}


Many thanks for the assistance.

You made the nodes children of the doc node, and that's what you got. If you move the edge after the two kids, you get

\documentclass[margin=1mm,xcolor=pdftex,dvipsnames]{standalone}

\usepackage{tikz}

\tikzset{every picture/.style={/utils/exec={\sffamily}},>=latex,align=center,font={\fontsize{10pt}{12}\selectfont}}

\begin{document}

\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=3.5cm},
level 2/.style={sibling distance=2cm},
tree node/.style={circle,draw,inner sep=1pt,minimum width=0.5cm},
every child node/.style={tree node},
every path/.append style={-latex}]

\node[circle,draw] {\&o1}
child {node {\&o2}
child {node {\&o3} edge from parent node[midway,above,sloped] {authors}}
child {node {\&o6} edge from parent node[midway,above,sloped] {title}}
edge from parent node[midway,above,sloped] {doc} }
child {node {\&o22} edge from parent node[midway,above,sloped] {doc}}
child {node {\&o34} edge from parent node[midway,above,sloped] {doc}}
;
\end{tikzpicture}

\end{document}


However, I would recommend using forest, which is arguably much more intuitive.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{forest}
\begin{document}
\forestset{el/.style={edge label={node[above,pos=0.5,sloped,font=\sffamily]{#1}}}}
\begin{forest}
for tree={circle,draw,l+=2em,s sep=5em,font=\sffamily,edge=-latex}
[\&o1
[\&o2,el=doc
[\&o3,el=authors]
[\&o6,el=title]
]
[\&o22,el=doc]
[\&o34,el=doc]
]
\end{forest}
\end{document}


• Ah, of course. Many thanks -- I missed the placement of the nodes. Thanks also for the suggestion to use forest. I need to learn it and this looks like a good time to do that. – ozsu Mar 20 at 10:28