如何绘制带有部分阴影节点的树状图?

如何绘制带有部分阴影节点的树状图?

我想画这个图形,但我不知道该怎么做。有人能帮我并给我一些建议吗?我很感激任何帮助!

这里至少是输入符号:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
Layer 3: Disjoint base lists $\mathcal{B}_{i,1}$ and $\mathcal{B}_{i,2}$ for $i=1,2,3,4$, $p_3=\frac{p_2}{2}$. 
Layer 2: $\mathcal{L}_1^{(2)}$, $\mathcal{L}_2^{(2)}$, $\mathcal{L}_3^{(2)}$, $\mathcal{L}_4^{(2)}$, $r_2$, $p_2=\frac{p_1}{2} + \Delta_2$. 
Layer 1: $\mathcal{L}_1^{(1)}$, $\mathcal{L}_2^{(1)}$, $r_1$, $p_1=\frac{p}{2}+\Delta_1$. 
Layer 0: $\mathcal{L}$, $\ell$, $p$. 
Strange symbol: $\bowtie$
\end{document}

在此处输入图片描述

答案1

这是您表格的近似复制品。

在此处输入图片描述

\documentclass{article}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
% for horizontal splits, drawing dashed splitting lines is a mess
% https://tex.stackexchange.com/a/34353/121799
\tikzset{pfft/.style={inner sep=1pt,rectangle split, rectangle split parts=2, draw, rectangle split
horizontal,rectangle split draw splits = false,
minimum height=1.2cm,
rectangle split part fill={white, gray!20!white},
%  append after command={% courtesy of Alenanno ref: https://tex.stackexchange.com/questions/287967/drawing-thin-line-around-a-multipart-tikz-shape#comment696552_287972
%       \draw[dashed] ($(\tikzlastnode.north west)!0.70!(\tikzlastnode.north east)$) 
%     -- ($(\tikzlastnode.south west)!0.7!(\tikzlastnode.south east)$);}
 }
}
\newcommand{\DrawVerticalDashedLine}[2][0.7]{%
\draw[dashed] ($(#2.north west)!#1!(#2.north east)$) -- ($(#2.south
west)!#1!(#2.south east)$);}

\begin{document}
\begin{tabular}{p{3cm}cp{3cm}}
 & & weight\\
Layer 3 & 
\begin{tikzpicture}[remember picture,baseline=(layer3.base)]
\node[draw](layer3){Disjoint base list $\mathcal{B}_{i,1}$ and $\mathcal{B}_{i,2}$ 
for $i=1,\dots 4$};
\end{tikzpicture}
& $p_3=\frac{p_2}{2}$\\[1cm]
Layer 2 & 
\begin{tikzpicture}[remember picture,baseline=(layer2a.base)]
\node[pfft](layer2a){~$\mathcal{L}_1^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer2a}
\node[pfft,right=0.4cm of layer2a](layer2b){~$\mathcal{L}_2^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer2b}
\node[pfft,right=0.4cm of layer2b](layer2c){~$\mathcal{L}_3^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer2c}
\node[pfft,right=0.4cm of layer2c](layer2d){~$\mathcal{L}_4^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer2d}
\end{tikzpicture}
 & $p_2=\frac{p_1}{2}+\Delta_2$\\[1cm]
Layer 1 & 
\begin{tikzpicture}[remember picture,baseline=(layer1a.base)]
\node[pfft](layer1a){~$\mathcal{L}_1^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer1a}
\node[pfft,right=2cm of layer1a](layer1b){~$\mathcal{L}_2^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer1b}
\end{tikzpicture}
 & $p_1=\frac{p}{2}+\Delta$\\[1cm]
Layer 0 & 
\begin{tikzpicture}[remember picture,baseline=(layer0a.base)]
\node[pfft](layer0a){~$\mathcal{L}_1^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer0a}
\end{tikzpicture}
 & $p$
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\draw[dashed] ($(layer3.south west)!0.1!(layer3.south east)$) -- (layer2a.north) --  ($(layer3.south west)!0.25!(layer3.south east)$);
\draw[dashed] ($(layer3.south west)!0.9!(layer3.south east)$) -- (layer2d.north) --  ($(layer3.south west)!0.75!(layer3.south east)$);
\node[below=0.3cm of layer3]{$\scriptscriptstyle \bullet~\bullet~\bullet$};
\node[above=0.2cm of layer1a]{$\bowtie$};
\node[above=0.2cm of layer1b]{$\bowtie$};
\draw (layer2a.south) -- (layer1a.north) -- (layer2b.south);
\draw (layer2c.south) -- (layer1b.north) -- (layer2d.south);
\node[above=0.2cm of layer0a]{$\bowtie$};
\draw (layer1a.south) -- (layer0a.north) -- (layer1b.south);
\end{tikzpicture}
\end{document}

我最终手工绘制了虚线,将方框的白色和灰色部分分开。根据这个帖子,这似乎是唯一的选择。我也没有将这些行添加为自动后置操作。这可能必须这样做才能rectangle split产生两个节点,这样\lastikznode就会混淆。如果有人知道如何解决这个问题,我会非常渴望知道。

编辑:这不会出错,并且最下面的框的尺寸与上面的框相同。(但我建议您自己尝试学习这些技巧,您会发现这更有趣。;-)

\documentclass{article}
\usepackage{amssymb}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
% for horizontal splits, drawing dashed splitting lines is a mess
% https://tex.stackexchange.com/a/34353/121799
\tikzset{pfft/.style={inner sep=1pt,rectangle split, rectangle split parts=2, draw, rectangle split
horizontal,rectangle split draw splits = false,
minimum height=1.2cm,
rectangle split part fill={white, gray!20!white},
%  append after command={% courtesy of Alenanno ref: https://tex.stackexchange.com/questions/287967/drawing-thin-line-around-a-multipart-tikz-shape#comment696552_287972
%       \draw[dashed] ($(\tikzlastnode.north west)!0.70!(\tikzlastnode.north east)$) 
%     -- ($(\tikzlastnode.south west)!0.7!(\tikzlastnode.south east)$);}
 }
}
\newcommand{\DrawVerticalDashedLine}[2][0.7]{%
\draw[dashed] ($(#2.north west)!#1!(#2.north east)$) -- ($(#2.south
west)!#1!(#2.south east)$);}

\begin{document}
\begin{tabular}{p{3cm}cp{3cm}}
 & & weight\\
Layer 3 & 
\begin{tikzpicture}[remember picture,baseline=(layer3.base)]
\node[draw](layer3){Disjoint base list $\mathcal{B}_{i,1}$ and $\mathcal{B}_{i,2}$ 
for $i=1,\dots 4$};
\end{tikzpicture}
& $p_3=\frac{p_2}{2}$\\[1cm]
Layer 2 & 
\begin{tikzpicture}[remember picture,baseline=(layer2a.base)]
\node[pfft](layer2a){~$\mathcal{L}_1^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer2a}
\node[pfft,right=0.4cm of layer2a](layer2b){~$\mathcal{L}_2^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer2b}
\node[pfft,right=0.4cm of layer2b](layer2c){~$\mathcal{L}_3^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer2c}
\node[pfft,right=0.4cm of layer2c](layer2d){~$\mathcal{L}_4^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer2d}
\end{tikzpicture}
 & $p_2=\frac{p_1}{2}+\Delta_2$\\[1cm]
Layer 1 & 
\begin{tikzpicture}[remember picture,baseline=(layer1a.base)]
\node[pfft](layer1a){~$\mathcal{L}_1^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer1a}
\node[pfft,right=2cm of layer1a](layer1b){~$\mathcal{L}_2^{(2)}$~ \nodepart{two} ${\scriptstyle r_2}$};
\DrawVerticalDashedLine{layer1b}
\end{tikzpicture}
 & $p_1=\frac{p}{2}+\Delta$\\[1cm]
Layer 0 & 
\begin{tikzpicture}[remember picture,baseline=(layer0a.base)]
\node[pfft](layer0a){~\makebox[\widthof{$\mathcal{L}_2^{(2)}$}][c]{$\mathcal{L}$}~ \nodepart{two}
\makebox[\widthof{${\scriptstyle r_2}$}][c]{${\scriptstyle \ell}$}};
\DrawVerticalDashedLine{layer0a}
\end{tikzpicture}
 & $p$
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\draw[dashed] ($(layer3.south west)!0.1!(layer3.south east)$) -- (layer2a.north) --  ($(layer3.south west)!0.25!(layer3.south east)$);
\draw[dashed] ($(layer3.south west)!0.9!(layer3.south east)$) -- (layer2d.north) --  ($(layer3.south west)!0.75!(layer3.south east)$);
\node[below=0.3cm of layer3]{$\scriptscriptstyle \bullet~\bullet~\bullet$};
\node[above=0.2cm of layer1a]{$\bowtie$};
\node[above=0.2cm of layer1b]{$\bowtie$};
\draw (layer2a.south) -- (layer1a.north) -- (layer2b.south);
\draw (layer2c.south) -- (layer1b.north) -- (layer2d.south);
\node[above=0.2cm of layer0a]{$\bowtie$};
\draw (layer1a.south) -- (layer0a.north) -- (layer1b.south);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容