Using TikZ, I want to create a nested rectangle split, with rounded corners, that looks like this:
desired result http://www.liacs.nl/~schraage/tikzsplit2.png
The question that most closely resembles this problem is Nested rectangles , however the proposed solution with two separate nodes fitted together in a virtual node seems rather complex and does not have the advantages of a regular splitted node such as margin handling, rounded corners, or nodepart definitions.
The closest thing I could come up with is this:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
\node (A) [rectangle split,rectangle split parts=2,draw,text centered,rounded corners]{
\textit{marriage}, 1850
\nodepart{second}
\begin{tabular}{c|c}
John & Mary \\
Smith & Jones\\
\end{tabular}
};
\end{tikzpicture}
\end{document}
But the tabular environment does not stretch to the borders of the node:
partial solution
What I want is something like this:
\node (A) [rectangle split,rectangle split parts=2,draw,text centered,rounded corners]{
\textit{marriage}, 1850
\nodepart{second}[rectangle split,rectangle split parts=2,rectangle split horizontal]
John\\Smith
\nodepart{second}
Mary\\Jones
};
or any other convenient nesting syntax.
Other solutions (e.g., a matrix
, or a straightforward fit
) are also appreciated.
Best Answer
Nesting TikZ pictures/nodes is always a tricky business. I try to avoid this.
A simply fix for your example (
tabular
lines do not touch the shape’s border) could be to set theinner ysep
to zero. Unfortunately, this cannot be done for the second node part separately. You’ll end up with a very tight node.I propose two solutions:
\Strut
;Simple
If you use this often, you might want to create a macro to which you only feed the tree text parts.
Code
Output
Complicated
This solution provides a
three parts
key that takes three arguments:Every argument can be preceded with a set of optional argument in brackets
[ … ]
(as done in the example).The
fit
library is used to fit a node around those three nodes (this is the one we actually want to draw).Re-arranging the order how the nodes are placed or making certain changed at the default options of the nodes one can achieve slightly different alignment.
Code
Output