How do I encircle a partial table in tikz?
While adding a \strut
would fixes the problem for a basic text, if you want to allow for more variable heights than adding a \vphantom
based on the height of the tallest entry is needed:
References:
- Strutting around: What's the difference between \strut, \mathstrut and \vphantom?
Code:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{braket}
\usetikzlibrary{matrix,fit}
\begin{document}
\newcommand{\objboxthreer}[7]{%
\newcommand{\MyStrut}{\vphantom{#1#2#3#4#5#6#7}}%
\begin{tikzpicture}
\matrix (m) [nodes={inner sep=2pt},matrix of nodes, nodes in empty cells,ampersand replacement=\&, row sep=0pt, column sep=0pt]
{
{#1\MyStrut} \& \& {#2\MyStrut} \& {#4\MyStrut} \& {#6\MyStrut} \& \\
\& \& {#3\MyStrut} \& {#5\MyStrut} \& {#7\MyStrut} \& \\
};
\node [
draw,
rounded corners=.5em,
inner sep=0pt,
outer sep=0pt,
minimum size=0pt,
fit=(m-1-2.north east)
(m-1-2.south east)
(m-1-3.north east)
(m-1-3.south east)
(m-1-4.north east)
(m-1-4.south east)
(m-1-5.north east)
(m-1-5.south east)
(m-1-6.north west)
(m-1-6.south west)] {};
%\draw [rounded corners=.5em] (m-1-2.south east) rectangle (m-3-6.north west);
\draw (m-1-3.north east) -- (m-1-3.south east);
\draw (m-1-4.north east) -- (m-1-4.south east);
\end{tikzpicture}%
}
\objboxthreer{d}{$p_s$}{$Y_d$}{$\left\{ \frac{p}{q} \right\}$}{$Y_d'$}{$\{p\}$}{$\Set{ x \in X | x > 5}$}
\end{document}
A solution with minimal tools, without matrix
but with shape multiple parts
\documentclass{article}
\usepackage{tikz}\usepackage{braket}
\usetikzlibrary{shapes.multipart}
\begin{document}
\setlength{\fboxsep}{0pt}
\begin{tikzpicture}[%
table shape/.style={rectangle split,
rectangle split part align=base,
rectangle split horizontal,
rectangle split parts=3,
rounded corners},
p3/.style={text width=18ex,align=center}]
\node [table shape,draw] (main)
{$p_s$
\nodepart{two}$p_d$
\nodepart[p3]{three}$\{p\}$};
\node [table shape] at ([yshift=-2em]main.center)
{$Y_d$
\nodepart{two}$Y'_d$
\nodepart[p3]{three}$\Set{ x \in X | x > 5}$};
\node at ([xshift=-3ex]main.text west) {d};
\end{tikzpicture}
\end{document}