考虑以下代码:
\documentclass[12pt, border=2mm]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={}
[A
[B
[C ]
[C ]
]
[1[2][3]]
[B
[C ]
[C ]
]
]
\end{forest}
\end{document}
是否有可能
忽略包含数字的节点来绘制树的第一部分,然后将包含数字的“子树”附加到根。
输出如下:
编辑 我的目标是将一棵“不重要”的小树放入一棵大树中。我只能通过在绘制树之前更改 y 坐标来使“不重要”的树足够小。但这会在树中留下一些空白:
\documentclass[12pt, border=2mm]{standalone}
\usepackage{forest}
\forestset{
unimportant/.style={
fit=rectangle,
for tree={
delay={content/.process={Ow {content}{\tiny ##1}}},
},
before drawing tree={
for tree={
delay={
inner sep=2pt,
typeset node,
y+/.process={Ow+n {level}{##1*20}},
},
},
},
},
}
\begin{document}
\begin{forest}
for tree={}
[A
[B
[C [D][D]]
[C [D][D]]
]
[1, unimportant[2[3][4]]]
[B
[C [D][D]]
[C [D][D]]
]
]
\end{forest}
\end{document}
答案1
如果您不介意命名节点,这相对容易。否则也完全可行,但不太直接。
\documentclass[border=10pt,12pt]{standalone}
\usepackage{forest}
\forestset{
unimportant/.style={
name=#1,
for tree={
font=\tiny,
},
before packing={pack, remove},
!u.before drawing tree={
append=#1,
delay={
for nodewalk={name=#1}{for tree={l*=.5, inner sep=2pt, delay=compute xy, delay n=2{y-/.option=l}}},
}
},
},
}
\begin{document}
\begin{forest}
for tree={}
[A
[B
[C [D][D]]
[C [D][D]]
]
[1, unimportant=this one [2[3][4]]]
[B
[C [D][D]]
[C [D][D]]
]
]
\end{forest}
\end{document}
答案2
这个问题让我很感兴趣。这是我尝试使用istgame
包裹。
\documentclass{standalone}
\usepackage{istgame}
\begin{document}
\begin{istgame}
% bigger tree
\tikzset{oval node/.style={ellipse node,draw=none}}
\xtdistance{12mm}{40mm}
\istrooto(0){A} \istb \istb \endist
\foreach \n in {1,2}
{
\xtdistance{12mm}{20mm}
\istrooto(B\n)(0-\n){B} \istb \istb \endist
\xtdistance{12mm}{10mm}
\istrooto()(B\n-1){C} \istb{}{\mbox{D}} \istb{}{\mbox{D}} \endist
\istrooto()(B\n-2){C} \istb{}{\mbox{D}} \istb{}{\mbox{D}} \endist
}
% tiny tree
\begin{scope}[font=\scriptsize]
\tikzset{oval node/.style={ellipse node,draw=none,minimum size=5pt,inner sep=0pt,outer sep=1.5pt}}
\xtdistance{3mm}{4mm}
\istrooto(00)([yshift=-2mm]0)[plain node] \istb \endist
\istrooto(1)(00-1){1} \istb<level distance=4mm> \endist
\istrooto(2)(1-1){2} \istb{}{3\ }[below,yshift=3pt] \istb{}{\ 4}[below,yshift=3pt] \endist
\end{scope}
\end{istgame}
\end{document}