1

Context: I would like to connect nodeparts in a TikZ graph that is positioned by the graphdrawing library. Unfortunately it fails to find the node, when I do attach the .first, .second, ... suffix.

Question:

  1. Is there something wrong in this example?
  2. Is there an easy way around this limitation?

Failing minimal working example with graphdrawing:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{graphdrawing,graphs,shapes}
\usegdlibrary{layered}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}[layered layout]
\node
    [rectangle split, rectangle split parts=4, text ragged]
     (NodeA)
    {
        Node A
        \nodepart{two}
        Part two
        \nodepart{three}
        Part three
        \nodepart{four}
        Part four
    };
\node
    [rectangle split, rectangle split parts=3, text ragged]
     (NodeB)
    {
        Node B
        \nodepart{two}
        Part two
        \nodepart{three}
        Part three
    };
\draw (NodeA.two) edge[->] (NodeB.three);
\end{tikzpicture}
\end{document}

Minimal working example without graphdrawing:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{graphs,shapes}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}
\node
    [rectangle split, rectangle split parts=4, text ragged]
     (NodeA)
    {
        Node A
        \nodepart{two}
        Part two
        \nodepart{three}
        Part three
        \nodepart{four}
        Part four
    };
\node
    [rectangle split, rectangle split parts=3, text ragged]
     (NodeB)
    {
        Node B
        \nodepart{two}
        Part two
        \nodepart{three}
        Part three
    };
\draw (NodeA.two) edge[->] (NodeB.three);
\end{tikzpicture}
\end{document}
  • It looks like you're mixing two ways in one. Why don't you simply use TikZ multipart nodes without the graphdrawing library? By the way if you comment out [layered layout] and specify nodes positions like 0,0 and 2,0, the line will appear. – Alenanno Jan 28 '16 at 16:33
  • Hi, thank you for looking into this. Unfortunately the real graph is bigger. Thus I want it to be arranged automatically. – Christoph Jan 28 '16 at 16:41
  • That can be done automatically by TikZ alone, too. But arranged how? Maybe if you clarified that it would be helpful. If you want to keep using graphdrawing I suggest you look at the Tikz manual and see how graphs are done there because I don't think you're respecting the syntax here (and that would explain the lack of results). – Alenanno Jan 28 '16 at 16:44
  • arranged in a sensible manner. I mean that's the purpose of the graph drawing algorithms, right? ;) I do not want to specify node positions because the graphs are just large. And yes, I do know about the forest package and actually use it for some visualizations too. I'll check the syntax again, thank you :) – Christoph Jan 28 '16 at 16:56
  • 1
    I think it doesn't work for much the same reason \draw (A) -- (B); doesn't work? – cfr Jan 28 '16 at 23:45
3

I am not convinced that the use of multipart nodes in combination with graph drawing is a felicitous match. In particular, it is rather hard to see how the automatic placement algorithms will be able to work properly in this kind of case.

With your example, for instance, I get the following result

cross-node result

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing,graphs,shapes.multipart}
\usegdlibrary{layered}
\begin{document}
\begin{tikzpicture}
  \graph [layered layout]
  {
    nodeA [as={Node A \nodepart{two} Part two \nodepart{three} Part three \nodepart{four} Part four}, rectangle split, rectangle split parts=4, text ragged]
    ,
    nodeB [as={Node B \nodepart{two} Part two \nodepart{three} Part three}, rectangle split, rectangle split parts=3, text ragged],
  };
  \draw (nodeA.two) edge[->] (nodeB.three);
\end{tikzpicture}
\end{document}

Doubtless this can be improved, but I wonder what work exactly the multipart nodes are intended to do and whether it would not be better, if automated layouts are required, to stick to nodes with simpler internal structures. (Or at least not rely on anchors to join them explicitly.)

The reason for these doubts is that it seems the only way to get the drawing done is to do it outside the scope of the \graph command, which means that the algorithm cannot take account of the desired edges.

I know next to nothing about the graph drawing libraries, however, so perhaps this is possible.

\begin{rant}
The Tikz manual documents the use of nodes here very poorly, in my opinion. 
Crucial information for actual use (e.g. how to include more than a single 
letter in a node) is either mentioned but not given ("you can do this, but 
we're not going to tell you how!") or provided only implicitly ("we won't 
bother to explain 'as' but if you trawl through all the examples, maybe 
you'll realise that it can be used to assign content which differs from 
the node name"). 
TikZ is great and the documentation is mostly overwhelming but good. 
However, the coverage of the graph drawing stuff seems more concerned to 
show off technical wizardry than to tell the reader anything useful. 
It wants to *impress* you.
Whether the reader can do anything useful with its wizardry is beside 
the point.
\end{rant}
  • When looking at the output I got from my graph I believe that nodes are positioned according to their adjacencies only which means that their position is not influenced by unrelated edges drawn near them, thus sometimes they partially hide edges that do not belong to them. Consequently I would expect that one can indeed change the endpoints of the edges. So thank you for investigating this. It really looks like it's not supported so far. – Christoph Jan 29 '16 at 13:31
  • The idea of drawing the edges outside the graphdrawing scope is good altough I think I'll prefer your second suggestion to rethink the structure of the nodes. I think I can put the text of the nodeparts as label on the edge until there is a better alternative. – Christoph Jan 29 '16 at 13:31

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.