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'm searching for a way to have orthogonal edges (only going horizontal and vertical) by default when I draw a tree. I can't seem to find a way to set this as the default style (without having to add edges with path each time).

enter image description here

\documentclass{article}
\usepackage{tikz}
%%% <
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
%%% >

\usetikzlibrary{arrows,shapes,positioning,shadows,trees}

\begin{document}
\begin{tikzpicture}
  \tikzstyle{every node}=[draw, rectangle, fill=gray!20]


  \node {root}
  child {node {left}}
  child {node {right}
    child {node {child}}
    child {node {child}}
  };
\end{tikzpicture}
\end{document}

I have included an example of the edges I'm searching for. There is not need for labels on the edges.

enter image description here

share|improve this question
    
Are you looking for the key edge from parent fork down? –  Claudio Fiandrino Mar 6 '13 at 14:17
    
The provided example is not a tree... You can obtain such lines using (node A) -| (node B) for drawing from node A to node B first horizontal, then vertical, or |- for the opposite? –  Lionel MANSUY Mar 6 '13 at 14:20
add comment

1 Answer

You can adjust further for your needs

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees,calc}

\begin{document}
\begin{tikzpicture}[
every node/.style={draw, rectangle, fill=gray!20},
edge from parent path={
(\tikzparentnode) |-   % Start from parent
($(\tikzparentnode)!0.5!(\tikzchildnode)$) -| % make an ortho line to mid point
(\tikzchildnode)}]                            % make another ortho to the target

  \node {root}
  child {node {left}}
  child {node {right}
    child {node {child}}
    child {node {child}}
  };
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
add comment

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.