0

Goal: I would like to have a more systematic way to draw a shape around multiple nodes in a tikz-qtree, where the nodes are connected by edges.

enter image description here

  • Currently, I manually adjust inner xsep and inner ysep and the rotation for each shape until it encircles just the nodes I want.
  • Otherwise, by default, fit will make a big regular shape (a square or circle) that tends to scoop up some nodes or labels I don't want.
  • How can I define a kind of shape once and for all and not have to manually adjust xsep and ysep and rotate each time?

\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

1 Answer 1

1

Torbjørn T. helped me find a solution! Thanks!

\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}

enter image description here

3
  • Torbjørn T.'s link led me to tex.stackexchange.com/questions/70648/… where I found something in a solution by tcpaiva which I used in the above.
    – Psven
    Commented Apr 3, 2022 at 17:46
  • Now I have a new question -- in my first method, the shapes encircling the nodes were themselves nodes, so I could link them to other nodes with edges. Tikz-qtree ensured that these edges neatly started at the boundary of the shape, and I could specify which side they started from with “south” etc. Now, the shapes encircling the nodes are paths. Does anyone know how I can draw lines from their boundaries to link them to other nodes?
    – Psven
    Commented Apr 3, 2022 at 20:00
  • Belatedly, put coordinates on the paths as you create them.
    – cfr
    Commented Jul 11, 2023 at 1:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .