2

I'm fairly new to tikz, but have discovered the graphs library, which works pretty well for my purposes. I'm using it to draw acylic directed graphs in a sort of tree shape (excuse my lack of terminology! ;) Thus, for a code like the following:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees}
\begin{document}
  \begin{tikzpicture}
  \graph[tree layout, sibling distance=1.3in]{
    "0" -> {"1" -> [edge label=Sub] "4" -> [edge label=Sub] {"2","3"}};
    "2" -> [edge label=Crd, swap] "3";
  };
  \end{tikzpicture}
\end{document}

I get the expected output:

enter image description here

However, when I do something like

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}
  \graph[tree layout, sibling distance=1.3in]{
    "0" -> [edge label=Sub] {"1" -> [edge label=Sub] "2","3"};
    "2" -> [edge label=Crd, swap] "3";
  };
  \end{tikzpicture}
\end{document}

I get:

enter image description here

although what I actually wanted is that the edge from 2 to 3 be drawn with a 90 degree angle or in other words I want to force node 3 to be on the same level as 2.

Edit: I simplified the graph and here some remarks on the graph properties to help explain my problem. Basically, in my framework there are 2 kinds of edges, subordinating ones that dominate a node in the structure (and may be drawn with an angle) and coordinating ones which need to be horizontal. There is a constraint on a well-formed graph of this kind that there may never be two coordinating edges starting from the same node (while for subordinating ones this is allowed). This should allow for coordinating ones to be invariably drawn horizontally. Can I impose these constraints on tikz in any way?

  • But 2 and 3 are not siblings. 1 and 3 are siblings. 2 is an only child. – cfr Jul 14 '16 at 23:22
  • You're absolutely right! I'll edit my question to make it clearer! – conipo Jul 15 '16 at 7:09
  • I found the nudge option for nodes, which allows me to hack the node to the right place. But a cleaner way would be preferred! – conipo Jul 15 '16 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.