这就是我现在所拥有的:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,automata}
\definecolor{light-gray}{gray}{0.6}
\begin{document}
\begin{tikzpicture}[line width=.1cm,shorten >=0pt,auto,on grid=false, every state/.style={minimum size=0pt}, level distance=2.0cm, level 1/.style={sibling distance=2cm}, level 2/.style={sibling distance=1cm}, level 3/.style={sibling distance=.5cm}]
\tikzstyle{every node}=[font=\tiny , circle, outer sep=0pt, inner sep=0pt]
\node[state] (S) {}
child {node[state] (S1) {}
child {node[state] (S11) {}
child {node[state] (S111) {} }
child {node[state] (S112) {} }
}
child {node[state] (S12) {}
child {node[state] (S121) {} }
child {node[state] (S122) {} }
}
}
child {node[state] (S2) {}
child {node[state] (S21) {}
child {node[state] (S211) {} }
child {node[state] (S212) {} }
}
child {node[state] (S22) {}
child {node[state] (S221) {} }
child {node[state] (S222) {} }
}
};
\end{tikzpicture}
\end{document}
我想要这样的东西:
实际上,这只是我正在处理的更大树的顶部,我必须对树中的许多路径执行此操作,所以我不想手动计算控制点。我宁愿只指定曲线应围绕的点(S,S1,S11,S111)以及应保持的点与曲线之间的距离。
这可能吗?任何帮助都将不胜感激!
编辑:
我尝试了 percusse 和 Torbjørn T. 的建议。在 tikzpicture 中添加了此代码:
\node[draw=none, above=5mm of S] (1p1) {};
\node[draw=none, left =5mm of S1] (1p2) {};
\node[draw=none, left =5mm of S11] (1p3) {};
\node[draw=none, below left =5mm and 2mm of S111] (1p4) {};
\node[draw=none, below right=5mm and 2mm of S111] (1p5) {};
\node[draw=none, right=5mm of S11] (1p6) {};
\node[draw=none, right=5mm of S1] (1p7) {};
\node[draw=none, below right=5mm and 2mm of S] (1p8) {};
\draw[black, line width=0.05cm] plot [smooth cycle] coordinates {(1p1) (1p2) (1p3) (1p4) (1p5) (1p6) (1p7) (1p8)};
\node[font=\small,rectangle,inner sep=5pt, above left=1.0cm and 0.5cm of 1p2] (curve) {Curve};
\path[->] (1p2) edge (curve);
最终结果如下:
与我的预期相反,只需通过复制粘贴和使用正则表达式,即可轻松使用此方法处理许多路径。虽然这暂时解决了我的问题,但这并不是我问题的答案。一个合适的解决方案仍然会非常有帮助!
答案1
这是我的尝试。基本上它画了一条“双线”下面选定节点的路径,使得线条看起来好像用曲线“包围”了选定节点。(请注意,我还将过时命令的使用更改\tikzstyle
为\tikzset
)
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,automata,backgrounds}
\definecolor{light-gray}{gray}{0.6}
\begin{document}
\begin{tikzpicture}[line width=.1cm,shorten >=0pt,auto,on grid=false, every state/.style={minimum size=0pt}, level distance=2.0cm, level 1/.style={sibling distance=2cm}, level 2/.style={sibling distance=1cm}, level 3/.style={sibling distance=.5cm}]
\tikzset{every node/.style={font=\tiny , circle, outer sep=0pt, inner sep=0pt}}
\node[state] (S) {}
child {node[state] (S1) {}
child {node[state] (S11) {}
child {node[state] (S111) {} }
child {node[state] (S112) {} }
}
child {node[state] (S12) {}
child {node[state] (S121) {} }
child {node[state] (S122) {} }
}
}
child {node[state] (S2) {}
child {node[state] (S21) {}
child {node[state] (S211) {} }
child {node[state] (S212) {} }
}
child {node[state] (S22) {}
child {node[state] (S221) {} }
child {node[state] (S222) {} }
}
};
\begin{scope}[on background layer]
\draw[double distance=5mm,line width=0.05cm,line join=round,line cap=round,red]
(S)--(S1)--(S12); % loose enclosure
\draw[double distance=2mm,line width=0.05cm,line join=round,line cap=round,blue]
(S)--(S2)--(S21)--(S212); % tight enclosure
\end{scope}
\end{tikzpicture}
\end{document}