作为后续问题绘制一个椭圆形到树形图片-tikz包那么,怎样才能制作一个更细的椭圆,围绕树中两个水平和垂直偏移的节点呢?
平均能量损失
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{shapes,fit}
\begin{document}
\begin{tikzpicture}
\Tree
[.\node(1){asdfasdf};
[.\node(2){hjklhjkl}; ]
[.qwerqwer ]
]
\node[draw,ellipse,fit=(1.north east)(2.south west)]{};
\end{tikzpicture}
\end{document}
结果
期望结果
(线条粗细和颜色无关紧要;请原谅我用鼠标徒手绘图的抖动。)
答案1
sloped
第一个想法:沿着连接这些节点的路径绘制椭圆:
\begin{tikzpicture}
\Tree
[.\node(1){asdfasdf};
[.\node(2){hjklhjkl}; ]
[.qwerqwer ]
]
\path (1.south) -- (2.north)
node[midway, sloped, draw, ellipse,
fit=(1.north east)(2.south west), inner sep=2pt]{};
\end{tikzpicture}
结果:
第二个想法:为了更精细的控制,\usetikzlibrary{calc}
以及let..in
计算椭圆所需大小的语法:
\begin{tikzpicture}
\Tree
[.\node(1){asdfasdf};
[.\node(2){hjklhjkl}; ]
[.qwerqwer ]
]
\path let
\p1 = ($(1.north east)-(2.south west)$),
\n1 = {veclen(\p1)}
in
(1.south) -- (2.north)
node[midway, sloped, draw, ellipse,
minimum width=\n1, minimum height=\n1/2] {};
\end{tikzpicture}
结果: