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 the inner 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:
- A simple one that follows Table Frames beyond simple lines but uses a big
\Strut
;
- A complex TikZ nodes-filled solution
Simple
If you use this often, you might want to create a macro to which you only feed the tree text parts.
Code
\documentclass[tikz,convert=false]{standalone}
\newcommand*{\ml}[2][c]{\tabular[t]{@{}#1@{}} #2 \endtabular}
\makeatletter
\newcommand*{\Strut}[1][1em]{\vrule\@width\z@\@height#1\@depth\z@\relax}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[rounded corners, draw, inner sep=+0pt] {%
\begin{tabular}{c|c}
\multicolumn{2}{c}{\textit{marriage}, 1850\Strut} \\\hline
\ml{\Strut John\\Smith} & \ml{\Strut Mary\\Jones}
\end{tabular}};
\end{tikzpicture}
\end{document}
Output

Complicated
This solution provides a three parts
key that takes three arguments:
- the text for the first top node,
- the text for the lower left node, and
- the text for the lower right node.
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
\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{fit}
\tikzset{
three parts left node/.style={
every three parts node,
name=qrr@tikz@tp@l,
at=(qrr@tikz@[email protected]),
anchor=north east,
outer sep=+0pt},
three parts right node/.style={
every three parts node,
name=qrr@tikz@tp@r,
at=(qrr@tikz@[email protected]),
anchor=north west,
outer sep=+0pt},
three parts top node/.style={
every three parts node,
name=qrr@tikz@tp@t,
outer sep=+0pt},
three parts node/.style={
inner sep=-.5\pgflinewidth,
minimum size=+0pt,
fit=(qrr@tikz@tp@l)(qrr@tikz@tp@r)(qrr@tikz@tp@t)},
every three parts node/.style={align=center},
three parts node after/.style={
insert path={
([xshift=\pgflinewidth] qrr@tikz@[email protected] west) edge[three parts node after edge 1/.try] ([xshift=-\pgflinewidth]qrr@tikz@[email protected] east)
([yshift=-.5\pgflinewidth]qrr@tikz@[email protected] east) edge[three parts node after edge 2/.try] ([yshift=\pgflinewidth] qrr@tikz@[email protected] west)}},
}
\makeatletter
\tikzset{
three parts/.code args={#1#2#3}{%
\pgfutil@ifnextchar[%
{\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts top node}}
{\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts top node}[]}#1\egroup\pgf@stop
\pgfutil@ifnextchar[%
{\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts left node}}
{\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts left node}[]}#2\egroup\pgf@stop
\pgfutil@ifnextchar[%
{\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts right node}}
{\expandafter\tikz@scan@next@command\qrr@tikz@split@nodeOpt{three parts right node}[]}#3\egroup\pgf@stop
\tikz@scan@next@command node[three parts node/.try]{}[three parts node after]\pgf@stop
}
}
\def\qrr@tikz@split@nodeOpt#1[#2]{node[#2,#1]\bgroup}
\makeatother
\begin{document}
\begin{tikzpicture}[three parts node/.append style={draw,rounded corners}]
\path [three parts={[blue!50!red]\textit{marriage}, 1850}{[blue]John\\Smith}{[red]Mary\\Jones}];
\end{tikzpicture}
\end{document}
Output
