Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a simple question about tikz tree, in which I want to have a edge label without that round box... I know that I have every node=circle, but I don't know how to change it for that specific element. Please help ;)

My code:

\documentclass{article} 
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=3.5cm},
level 2/.style={sibling distance=1cm}]
\tikzstyle{every node}=[circle,draw]

\node (Root) [red] {3}
    child {
    node {1} 
    child { node {4} edge from parent node[left] {help!} }
    child { node {1} }
    child { node {3} }
}
child {
    node {2}
    child { node {3} }
    child { node {2} }
    child { node {5} }
};

\end{tikzpicture}
\end{document}
share|improve this question

3 Answers 3

As with all simple trees like this, it's almost always easier to use the tikz-qtree package:

\documentclass{article} 
\usepackage{tikz-qtree}

\begin{document}
\begin{tikzpicture}[every tree node/.style={draw,circle},
   level distance=1.25cm,sibling distance=.5cm, 
   edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}]
\Tree [.\node[red] {3}; 
    [.1  
      \edge node[auto=right] {Help!};  
      [.4  ] [.1 ] [.3 ]
    ]
    [.2
      [.3 ] [.2 ] [.5 ]
    ] ]
\end{tikzpicture}
\end{document}

output of code

share|improve this answer

As Alan Munn says in his answer, using tikz-qtree could be preferable. However, if, for some reason, you want to stick to your code, you can use the draw=none option:

\documentclass{article} 
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=3.5cm},
level 2/.style={sibling distance=1cm}]
\tikzstyle{every node}=[circle,draw]

\node (Root) [red] {3}
    child {
    node {1} 
    child { node {4} edge from parent node[left,draw=none] {help!} }
    child { node {1} }
    child { node {3} }
}
child {
    node {2}
    child { node {3} }
    child { node {2} }
    child { node {5} }
};

\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

There is also a style called every child node that is applied to every node in a child and leaves the others unchanged. This will mostly do what you want, but you will have to manually apply the style to the root node.

\documentclass{article} 
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
\begin{tikzpicture}[level distance=1.5cm,
level 1/.style={sibling distance=3.5cm},
level 2/.style={sibling distance=1cm},
tree node/.style={circle,draw},
every child node/.style={tree node}]

\node[tree node] (Root) [red] {3}
    child {
    node {1} 
    child { node {4} edge from parent node[left] {help!} }
    child { node {1} }
    child { node {3} }
}
child {
    node {2}
    child { node {3} }
    child { node {2} }
    child { node {5} }
};

\end{tikzpicture}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.