问题:
我有一棵 MWE 树,我想在 G 下添加一个带有标签 I 的节点。该怎么做?
\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{center}
\begin{tikzpicture}
\node [circle,draw]{F} [level distance=10mm,sibling distance=25mm]
child { node [circle,draw]{D} [level distance=10mm ,sibling distance=15mm]
child {node [circle,draw] {B}
child {node [circle,draw] {A}}
child {node [circle,draw]{C}}}
child {node [circle,draw]{E}}
}
child {node [circle,draw] {J} [level distance=10mm ,sibling distance=15mm]
child {node [circle,draw] {G}}
child {node [circle,draw]{K}}
};
\end{tikzpicture}
\end{center}
\end{document}
答案1
像这样:
\documentclass[10pt]{article}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\begin{center}
\begin{tikzpicture}
\node [circle,draw]{F} [level distance=10mm,sibling distance=25mm]
child { node [circle,draw]{D} [level distance=10mm ,sibling distance=15mm]
child {node [circle,draw] {B}
child {node [circle,draw] {A}}
child {node [circle,draw]{C}}}
child {node [circle,draw]{E}}
}
child {node [circle,draw] {J} [level distance=10mm ,sibling distance=15mm]
child {node [circle,draw] {G}
child {node [circle, draw] {I}} % <--- added node
}
child {node [circle,draw]{K}}
};
\end{tikzpicture}
\end{center}
\end{document}
附录: 根据您的评论的解决方案(如果我理解正确的话):
\documentclass[10pt]{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\node [circle,draw]{F} [level distance=10mm,sibling distance=25mm]
child { node [circle,draw]{D} [level distance=10mm ,sibling distance=15mm]
child {node [circle,draw] {B}
child {node [circle,draw] {A}}
child {node [circle,draw]{C}}}
child {node [circle,draw]{E}}
}
child {node [circle,draw] {J} [level distance=10mm ,sibling distance=15mm]
child {node [circle,draw] {G}
child[missing] % <--- added node
child {node [circle, draw] {I}} % <--- added node
}
child {node [circle,draw]{K}}
};
\end{tikzpicture}
\end{center}
\end{document}
使用forest
包的替代解决方案:
\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{center}
\begin{forest}
for tree = {
circle,
draw,
minimum size=1.5em,
inner sep=2pt,
s sep+=4mm
}
[F
[D
[B
[A]
[C]
]
[E]
]
[J,fit=band
[G
[,phantom]
[I]
]
[K]
]
]
\end{forest}
\end{center}
\end{document}
得出类似的结果: