将形状拟合到 tikz-qtree 中的节点

将形状拟合到 tikz-qtree 中的节点

目标:我想要一种更系统的方法来围绕多个节点绘制形状tikz-qtree,其中节点通过边连接。

在此处输入图片描述

  • 目前,我手动调整inner xsep每个inner ysep形状的旋转,直到它刚好围绕我想要的节点。
  • 否则,默认情况下fit会制作一个大的规则形状(正方形或圆形),倾向于舀起一些我不想要的节点或标签。
  • 我怎样才能一劳永逸地定义一种形状,而不必每次都手动xsep调整?yseprotate

\documentclass{standalone}

\usepackage{tikz,tikz-qtree}

\begin{document}

\begin{tikzpicture}
\Tree[.\node(T){T}; Subject [.\node(Aux){Aux}; Aux [.\node(Asp){Asp}; Adverb [.\node(V){V}; Verb Object ] ] ] ]
\node[draw,fit=(T)(Aux),style={ellipse,draw,red,inner xsep=0pt,inner ysep=-10pt,rotate=-40}](maa){};
\node[draw,fit=(Asp)(V),style={rounded corners,inner ysep=-8pt,rotate=-28}]{};
\end{tikzpicture}

\end{document}

答案1

Torbjørn T. 帮我找到了解决方案!谢谢!

\documentclass{standalone}

\usepackage{tikz,tikz-qtree}
\usetikzlibrary{matrix}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\tikzset{
    my box/.style = {
        , line cap = round
        , line join = round
    }
}

\newcommand{\highlight}[3]{
    \path [my box, line width = 1.15 * #1, draw = #2] #3;

    \pgfmathsetmacro{\innerlinewidth}{1.1 * #1}
    \path [my box, line width = \innerlinewidth, draw = #2!10] #3;
}

\begin{document}

\begin{tikzpicture}
\Tree[.\node(T){T}; Subject [.\node(Aux){Aux}; Aux [.\node(Asp){Asp}; Adverb [.\node(V){V}; Verb Object ] ] ] ]
\begin{pgfonlayer}{background}
    \highlight{12mm}{blue}{(Asp) -- (V)}
\end{pgfonlayer}
\end{tikzpicture}

\begin{tikzpicture}
\Tree[.\node(T){T}; Subject [.\node(Aux){Aux}; Aux [.\node(Asp){Asp}; Adverb [.\node(V){V}; Verb Object ] ] ] ]
\begin{pgfonlayer}{background}
    \highlight{12mm}{red}{(T) -- (V)}
\end{pgfonlayer}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容