2

I have a graph with two chains like this:

\begin{document}
\tikz []
\graph [layered layout, components go right top aligned, nodes=draw]
{
  {[nodes={name prefix=cat1}]
    cat1 -> {100, 200 [>minimum layers=2]};
    200  -> {210, 300};
    300  -> {400, 420, 450};
  };
  {[nodes={name prefix=cat2}]
    cat2 -> 101 -> 102 -> 203 -> {204, 408};
  };
%  (cat2102) -> (cat1200);
};
\end{document}

In the last commented line I try to draw an edge between nodes on the two chains but tikz complains that the nodes are not in the graph. How can I accomplish this? You have to compile the above with luatex.

2

You have to use the key /tikz/graphs/name to use a prefix for the nodes on a graph. But then there is a separator added after the prefix. The default of /tikz/graphs/name separator is a space.

\documentclass[margin=5pt]{standalone}
\usepackage{luatex85}

\usepackage{tikz}
\usetikzlibrary{graphs}
\usetikzlibrary{graphdrawing}
\usegdlibrary{layered}

\begin{document}
\tikz []
\graph [layered layout, components go right top aligned, nodes=draw]
{
  {[name=cat1]
    cat1 -> {100,200 [>minimum layers=2]};
    200  -> {210, 300};
    300  -> {400, 420, 450};
  };
  {[name=cat2]
    cat2 -> 101 ->102-> 203 -> {204, 408};
  };
  (cat2 102) -> (cat1 200);
};
\end{document}

Result:

enter image description here

Remark: If you want to use a different name separator you have to change its value before you set the name key.

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.