I want to create a custom node shape that eventually looks like this:
It’s easy to draw a TikZ picture that renders the above, using multiple nodes. However, I want it to be a single node, so that I can use the forest package to draw trees made of these nodes. And also, I got curious ;-)
After reading the PGF manual, my impression is that this can be accomplished with a custom shape with five parts: (1) text: “Lorem ipsum…”, (2) label: “all”, (3) id: “12345”, (4) hello: “hello world”, (5) value: “4/5”.
I started with just the text (“Lorem ipsum…”) and the label (“all”) part and already ran into problems. The following code is my attempt.
\documentclass[tikz,margin=2mm]{standalone}
\newsavebox{\pgfnodepartlabelbox}
\makeatletter
\pgfdeclareshape{mynode}{
\nodeparts{text,label}
\savedanchor{\northeast}{
\pgf@y=1.\ht\pgfnodeparttextbox
\advance\pgf@y by -0.\dp\pgfnodeparttextbox
\pgf@x=1.\wd\pgfnodeparttextbox
\advance\pgf@x by \wd\pgfnodepartlabelbox
}
\savedanchor{\southwest}{
\pgf@y=-.0\ht\pgfnodeparttextbox
\advance\pgf@y by -1.0\dp\pgfnodeparttextbox
\pgf@x=.0\wd\pgfnodeparttextbox
}
\savedanchor{\joint}{
\pgf@y=0pt
\pgf@x=1.\wd\pgfnodeparttextbox
}
\anchor{label}{\joint}
\foreach \anchor in {center} {%
\inheritanchor[from=rectangle]{\anchor}%
}
\inheritbackgroundpath[from=rectangle]
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node [mynode, draw=red, text width=4cm, align=justify]
at (0,0) {
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
\nodepart{label}
foo
};
\end{tikzpicture}
\end{document}
Above code outputs:
But I want it to output (the colors and spacings don’t matter for now, I think I can handle these):
So my questions:
- Is it even a good idea to solve my problem with a custom multipart shape? Or should the other parts be somehow passed as options?
- How can I rotate a single node part? The “foo” in my attempt is not rotated.
- How can I define the text width of a single node part? The “foo” part is my attempt has a width of 4cm like the “Lorem ipsum…” part, but I only want the “Lorem ipsum…” to be 4cm.


