4

I want to draw two graphs combined (actually, it is a large tree that does not fit on the page, see bonus question). However, I cannot find a way to position a \graph.

Here is an example:

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,graphdrawing.trees}
\begin{document}
\begin{tikzpicture}
      \begin{scope}%
        [level distance=10mm,text depth=.1em,text height=.5em]
        \graph[tree layout, grow=up]{
          x -- {y,z}
        };
        \graph[tree layout, grow=down]{
          a -- {b,c}
        };
      \end{scope}
\end{tikzpicture}
\end{document}

How does one put a node between x and a (i.e. have x above that node and a below)?

Bonus question: As mentioned, the reason for my question is that I want to layout a tree that does not fit on one page. My idea is to move one sub tree upwards and turn it around. Is there an idiomatic way to achieve this via \graph?

2

You can also use what the manual calls sublayouts to draw your graph, like this:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,graphdrawing.trees,graphdrawing.layered}
\begin{document}
\begin{tikzpicture}
    \begin{scope}[level distance=10mm,text depth=.1em,text height=.5em]
        \graph[layered layout]{
            //[tree layout, grow=up] { x -- {y,z} };
            x -- A -- a;
            //[tree layout, grow=down] { a -- {b,c} };

        };
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

1

\graph is just \path graph, so you could do \path (x,y) graph... to position them. The default coordinate is (0,0) I'd think.

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,graphdrawing.trees}
\begin{document}
\begin{tikzpicture}
      \begin{scope}%
        [level distance=10mm,text depth=.1em,text height=.5em]
        \node (a) {A};
        \path (0,0.5) graph[tree layout, grow=up]{
          x -- {y,z}
        };
        \path (0,-0.5) graph[tree layout, grow=down]{
          a -- {b,c}
        };
      \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

  • This does not work with Cartesian placement strategy. – ScumCoder May 24 at 16:55
  • @ScumCoder I'm not really an expert on this stuff, so if you're wondering if it's possible to make it work with Cartesian placement, I suggest you ask a new question with an example showing that it doesn't. – Torbjørn T. May 26 at 8:21
  • My comment was in no way a complaint or criticism, I just wanted to save time for people with the same problem as me if they stumble upon your question and think that it's the solution. I created a question for my own problem here. – ScumCoder May 26 at 12:16

Your Answer

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

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