答案1
对于第一个图,我建议使用forest
。使用name=
来命名节点。然后您可以tikz
在最后使用普通命令。
\documentclass{article}
\usepackage{forest}
\usetikzlibrary{decorations.pathreplacing}
\tikzset{mytext/.style={font=\tiny, text=teal}}
\begin{document}
\begin{forest}
for tree={circle, fill=teal, inner sep=1pt, outer sep=0pt, s sep=5mm}
[
[, label={[mytext]180:{1}}[,name=a1][,name=a2][,name=a3]]
[, name=n2, label={[mytext]180:{2}}[,name=b1][,name=b2][,name=b3]]
[, name=n3, label={[mytext]180:{$d$}}[,name=c1][,name=c2][,name=c3]]
]
\path(n2)--node{$\cdots$}(n3);
\path(a2)--node{$\scriptstyle\cdots$}(a3);
\path(b2)--node{$\scriptstyle\cdots$}(b3);
\path(c2)--node{$\scriptstyle\cdots$}(c3);
\draw[decorate, teal, decoration={brace, mirror, raise=3pt}](a1.south west)--node[yshift=-2ex, mytext]{$d$}(a3.south east);
\draw[decorate, teal, decoration={brace, mirror, raise=3pt}](b1.south west)--node[yshift=-2ex, mytext]{$d$}(b3.south east);
\draw[decorate, teal, decoration={brace, mirror, raise=3pt}](c1.south west)--node[yshift=-2ex, mytext]{$d$}(c3.south east);
\end{forest}
\end{document}
答案2
对于第一张图,请遵循 Alan Munn 的建议。对于其他图,请尝试以下代码:
\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=.5]
\filldraw[yellow] (1,1) rectangle (17,11);
\path (2,2)--(9,10) node[inner sep=0pt,pos=.2] (a) {};
\path (16,2)--(9,10) node[inner sep=0pt,pos=.2] (b) {};
\filldraw[green!60!black] (2,2)--(9,10)--(16,2);
\filldraw[gray!20] (a)--(9,10)--(b);
\path[black] (a)--(b) node[pos=.5,above] () {n-th level};
\end{tikzpicture}
\hspace{.2cm}
\begin{tikzpicture}[scale=.5]
\filldraw[yellow] (1,1) rectangle (17,11);
\path (2,2)--(9,10) node[inner sep=0pt,pos=.2] (a1) {};
\path (16,2)--(9,10) node[inner sep=0pt,pos=.2] (b1) {};
\path (2,2)--(16,2) node[inner sep=0pt,pos=.2] (c) {};
\filldraw[gray!20] (2,2)--(9,10)--(16,2);
\filldraw[green!60!black] (a1)--(2,2)--(c);
\draw[black] (a1)--(b1) node[pos=.5,above] () {n-th level};
\end{tikzpicture}
\end{document}
输出为: