3

I'm trying to make use of the newer (pgf > 3.0) graphdrawing layouts to do class diagrams, but I can't seem to figure out how to get arrows to attach to the outline of a rectangle split. I've read about the anchor points for a rectangle split in the documentation at https://www.ctan.org/pkg/pgf, but I can't figure out how to make use of them.

Basically, in the example below the arrows should attach at the outside of the rectangle split. I have no idea why they are attaching instead to the middle "two" box. Any ideas?

example

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,arrows,shapes.multipart}
\usegdlibrary{layered}
\begin{document}

\tikzset{object/.style={draw, rectangle split, rectangle split parts=3,
    rounded corners, rectangle split part align={center,left,left}},
    align=left}
\def \properties {\nodepart{two}}
\def \methods {\nodepart{three}}

\begin{tikzpicture} [layered layout, >=latex]

\node(obj)[object] {
obj
\properties
+property: class
\methods
method(inputs): outputs};

\node(foo)[object] {
foo
\properties
ids: cell array\\
xyz: Nx3 array
\methods
compute():\\
plot(): handle
};

\node(bar)[object] {
bar
\properties
ids: cell array\\
xyz: Nx3 array
\methods
compute():\\
plot(): handle
};

\graph[use existing nodes]
{
(obj) -> (foo);
(foo) -> [>=open diamond] (bar);
};

\end{tikzpicture}
\end{document}
  • I don't think layered layout is intended to be used for positioning nodes outside of the \graph command. If you explicitly position the nodes using the at syntax and remove the layered layout from the picture options, the connections use the expected anchors. – Mark Wibrow Mar 16 '15 at 17:15
  • This is what I was beginning to suspect, Mark, that anchors were somehow incompatible with algorithmic graphdrawing. But the automatic layout algorithms of PGF 3.0 are exactly what I'm hoping to leverage to make class diagrams in latex. I know there are packages which do class diagrams in latex out there, but from what I've seen they don't have compact syntaxes and/or don't do automatic layout. – Nick Mar 17 '15 at 12:04

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.