# Set font for each part of multipart shape in TikZ

I'm looking for a way to set the font for each part of a multipart shape, rather than having to repeat the font commands for each line. Here is an example of what I am trying to achieve:

\documentclass[varwidth,convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}

\tikzset{
labeled node/.style={
rectangle split, rectangle split parts=2,
rectangle split draw splits=false,
rounded corners,
very thick,
draw=orange!50,
rectangle split part fill={orange!50, none},
align=left,
}
}

\begin{document}

\begin{tikzpicture}
\node[labeled node] {
\sffamily\bfseries\boldmath
node $v_1$
\nodepart{two}
\slshape
Contents of\\
\slshape
node $v_1$.
};
\end{tikzpicture}

\end{document}


In the example, I must manually set the bold font for the first part, and the slshape for each line of the second part, which would be annoying if I have to create tons of these multipart shapes in my document and want them all identically styled.

How can I adjust the definition of labeled node/.style so as to make this font setting automatic?

When you do \nodepart{two}, a style called every two part node is defined, and added at the start of the nodepart. As such, you can define this style and it will be used for all nodeparts called two, and if you have font=\slshape in a style the font declaration doesn't have to be added for each line.

For example:

\documentclass[border=4mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}

\tikzset{
labeled node/.style={
rectangle split, rectangle split parts=2,
rectangle split draw splits=false,
rounded corners,
very thick,
draw=orange!50,
rectangle split part fill={orange!50, none},
align=left,
font=\sffamily\bfseries\boldmath
},
labeled file/.style={
rectangle split, rectangle split parts=2,
rectangle split draw splits=false,
rounded corners,
very thick,
draw=blue!50,
rectangle split part fill={blue!50, none},
align=left,
font=\sffamily\bfseries\boldmath
},
every two node part/.style={font=\slshape},
every twofile node part/.style={font=\bfseries}
}
\let\pgfnodeparttwofilebox=\pgfnodeparttwobox
\begin{document}

\begin{tikzpicture}
\node[labeled node] {
node $v_1$
\nodepart{two}
Contents of\\
node $v_1$.
};
\end{tikzpicture}

\begin{tikzpicture}
\node[labeled file] {
node $v_2$
\nodepart{twofile}
That of\\
node $v_2$.
};
\end{tikzpicture}
\end{document}

• This is good enough for what I wanted, though it only works for one style. E.g., if I had labeled node and a labeled file or something, what if I wanted a different style for part two of the labeled file? Nov 5 '15 at 23:52
• @user3188445 Well you would need to give a different name to the second part in of labeled file, e.g. \nodepart{twofile}, and set the every twofile node part style to whatever you'd prefer. Nov 5 '15 at 23:56
• But when I say \nodepart{twofile}, it gives an error. Do I have to define some new type of multipart shape for this to work? Nov 6 '15 at 0:12
• Oh, I guess I just need to say: \let\pgfnodeparttwofilebox=\pgfnodeparttwobox - no, that compiles, but doesn't show the parttwo part. So I'm still not sure how to make your suggestion work. Nov 6 '15 at 0:14
• @user3188445 I honestly don't know why that throws an error ... Nov 6 '15 at 0:19