2

I have been encountering some problems with figuring out how to put the arrows where I want them.

Essentially, I would like to put my arrows at center of each of the following trees, but they keep scrambling over, possibly due to the page margins.

Is there anyone that could think of a solution?

\documentclass{article}
\usepackage{linguex}
\usepackage{qtree} 
\usepackage{multicol}
\usepackage{tikz}
\begin{document}
\begin{multicols}{3}
\ex. \small
\a. \Tree [.DP [.NP ]. NP ].DP
\b. \Tree [.DP [.NP ]. NP ].DP
\c. \Tree [.DP [.NP ]. NP ].DP

\end{multicols}

\begin{center}
\begin{tikzpicture}
\draw[->] (-2, 0) -- (-2, -0.5) node[anchor=north] {[bla]};
\draw[->] (3, 0) -- (3, -0.5) node[anchor=north] {[blu]};
\draw[->] (5, 0) -- (5, -0.5) node[anchor=north] {[bli]};   
\end{tikzpicture}
\end{center}

\end{document}
  • Genaraly one uses \tikzmark (tikzlibrary tikzmark) to locate the end points in the text, then the [remember picture,overlay] options to draw the arrows. It takes two runs to locate relative origins, but alignment is generally easy and perfect. OTOH, I have no idea what \Tree does. – John Kormylo Dec 2 '16 at 17:52
  • Thanks for the hint, but can you be more specific? I'm a newbie with tikz. :) – RobertP. Dec 2 '16 at 20:16
  • There are several examples on this site using tikzmark to locate arrows (mostly involving tabulars). See tex.stackexchange.com/questions/339719/… for example. – John Kormylo Dec 3 '16 at 5:19
  • @JohnKormylo It uses picture, I think. At least, my hack uses picture and I started from qtree's code, so it certainly used picture 4 years ago. – cfr Dec 4 '16 at 0:06
3

Just realized, you can actually put a tree in a \node. One important thing to note is that you must have a space between the last part of the tree and the closing }; of the node (perhaps obvious to you, but it caught me at first).

\documentclass{article}
\usepackage{linguex}
\usepackage{qtree} 
\usepackage{multicol}
\usepackage{tikz}
\begin{document}
\begin{multicols}{3}
\ex. \small
\a. \begin{tikzpicture}
     \node (a) {\Tree [.DP [.NP ]. NP ].DP }; % space before }; is necessary
     \draw (a.south) -- +(0,-0.5) node[below] {[bla]};
    \end{tikzpicture}
\b. \begin{tikzpicture}
     \node (a) {\Tree [.DP [.NP ]. NP ].DP };
     \draw (a.south) -- +(0,-0.5) node[below] {[blu]};
    \end{tikzpicture}
\c. \begin{tikzpicture}
     \node (a) {\Tree [.DP [.NP ]. NP ].DP };
     \draw (a.south) -- +(0,-0.5) node[below] {[bli]};
    \end{tikzpicture}
% an empty line before \end{multicols} is necessary

\end{multicols}
\end{document}

enter image description here

Original answer

If switching to tikz-qtree is an option, you can draw the arrow in the same tikzpicture as the \Tree:

enter image description here

\documentclass{article}
\usepackage{linguex}
\usepackage{tikz-qtree}
\usepackage{multicol}
\usepackage{tikz}
\begin{document}
\begin{multicols}{3}
\ex. \small
\a. \begin{tikzpicture}[baseline]
     \Tree [.DP [.NP ] [.NP ] ]
    \draw [->] (current bounding box.south) -- +(0,-0.5) node[below] {[bla]};
    \end{tikzpicture}
\b. \begin{tikzpicture}[baseline]
    \Tree [.DP [.NP ] [.NP ] ]
    \draw [->] (current bounding box.south) -- +(0,-0.5) node[below] {[bla]};
    \end{tikzpicture}
\c. \begin{tikzpicture}[baseline]
    \Tree [.DP [.NP ] [.NP ] ]
    \draw [->] (current bounding box.south) -- +(0,-0.5) node[below] {[bla]};
    \end{tikzpicture}
\end{multicols}
\end{document}
  • very nice. however, my actual trees are a bit more complicated than those that I presented in my MWE, and as far as I know tikz-qtree does not fully supports what I need. Any other option? – RobertP. Dec 2 '16 at 20:11
  • @RobertP. I never draw such trees, though I note from tikz-qtree's manual that there's a package called tikz-qtree-compat that makes some more qtree features available in tikz-qtree. You could of course make the trees manually with TikZ, but that's a lot more work, so not an ideal option. Another popular tree-drawing package is forest, which I understand is really powerful, but I've never really used it. – Torbjørn T. Dec 3 '16 at 18:27
  • @RobertP. Just thought of a workaround, see above. – Torbjørn T. Dec 3 '16 at 18:35
  • that sounds interesting! didn't think of embedding a \Tree command inside a node. thanks! – RobertP. Dec 3 '16 at 19:28
  • Nice! Since qtree isn't TikZ-based, you aren't nesting tikzpictures ;). I'd still use Forest. (I had my fill of qtree and it just can't do a lot of things or can't do them without your having to wade through treacle. But it was certainly useful before there were better options available.) – cfr Dec 4 '16 at 0:02
3

Here's a Forest solution which defines a new style, add arrow=<text>. This can be used in the tree's preamble (after the start of the Forest tree and before the specification of the tree itself). It draws an arrow from the centre of the bottom of the tree's bounding box down to a node containing the <text> argument wrapped in square brackets.

\documentclass{article}
\usepackage{linguex}
\usepackage{multicol}
\usepackage[linguistics]{forest}
\forestset{%
  add arrow/.style={
    tikz+={%
      \draw [->] (current bounding box.south) -- +(0,-.5) node [anchor=north] {[#1]};
    },
  },
}
\begin{document}
\begin{multicols}{3}
  \ex. \small
  \a. \Forest{add arrow=bla [DP[NP][NP]]}
  \b. \Forest{add arrow=blu [DP[NP][NP]]}
  \c. \Forest{add arrow=bli [DP[NP][NP]]}

\end{multicols}
\end{document}

centred arrows below trees

As a bonus, you don't have to worry about remembering spaces before closing brackets of any kind. (It won't matter if the spaces are there, as they would be in qtree, but it won't care if they aren't. [Forest is worth switching to, if only for this feature, in my opinion!]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.