0

I would like to create a style I can give to a node such that it is a multipart node (2-part, say) with one part's text fixed.

I know I how to create multipart nodes using, e.g., circle split and how to then select the lower part with \nodepart{lower}. I also know that I can set default text using node contents, but this seems only to apply to simple nodes.

How can I set a default text to arbitrary node parts of multipart nodes?

1
  • @Zarko: I am aware of this; circle split was an example.
    – equaeghe
    Apr 21 '16 at 19:03
4

Probably it's not what you want but if there is no better solution ...

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,shapes.multipart}

\begin{document}
\begin{tikzpicture}[mynode/.style={rectangle split, rectangle split parts=2, draw, node contents=#1},
mynode/.default={A\nodepart{two}B}]
\node (A) [mynode];
\node[right=5mm of A] (B) [mynode={C}];
\node[right=5mm of B] (C) [mynode={\nodepart{two}D}];
\end{tikzpicture}
\end{document}

enter image description here

If you want always the same part with fixed contents, define it inside .style and left the other one as parameter:

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,shapes.multipart}

\begin{document}
\begin{tikzpicture}[mynode/.style={rectangle split, rectangle split parts=2, draw, node contents={#1\nodepart{two}Constant}},
]
\node (A) [mynode=A];
\node[right=5mm of A] (B) [mynode=B];
\node[right=5mm of B] (C) [mynode=C];
\end{tikzpicture}
\end{document}

enter image description here

1
  • 1
    Acually, your second solution is exactly what I want. (I tried something similar, but it didn't work, probably because I'm using it in a \graph; your code also doesn't work there... but that's material for another question.)
    – equaeghe
    Apr 21 '16 at 20:41

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.