2

I want to create a custom node shape that eventually looks like this:

enter image description here

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:

Actual output without rotated label part

But I want it to output (the colors and spacings don’t matter for now, I think I can handle these):

Desired output with rotated label part

So my questions:

  1. 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?
  2. How can I rotate a single node part? The “foo” in my attempt is not rotated.
  3. 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.
SebGlav
  • 19,186
Lumen
  • 283
  • I recommend using like-node pic as in this answer https://tex.stackexchange.com/a/616995/140722 – Black Mild Jan 06 '22 at 14:56
  • I don’t see how I can use like-node pics with the forest library. Maybe multipart nodes are not fit for my task. I might have to define all but the Lorem ipsum… text via options and do something like https://tex.stackexchange.com/a/147141. – Lumen Jan 07 '22 at 11:18

0 Answers0