5

I want to create a dependency diagram such as the following: dependency diagram

So far, I have done this using TikZ:

\documentclass{article}
\usepackage{tikz}
\usepackage{calc}

\begin{document}
\def\mytext{The man}

\newlength{\basewidth}
\setlength{\basewidth}{\widthof{\mytext}}

\begin{tikzpicture}[
    firstnode/.style={
      shape = rectangle,
      inner sep = 2pt,
      anchor=south west,
    }
    ]
    \draw[thin] (0,0) -- (\basewidth + 2ex,0);
    \draw[thin] (0,0) -- (0, 1.5em);
    draw (0,0) \node[firstnode,
    minimum width = \basewidth] {\mytext};
  \end{tikzpicture}
\end{document}

Which gives me the following output:

my output

How may I complete the diagram (in repeatable, efficient way)?

  • Welcome! Did you have a look at the forest package? – user121799 Feb 25 '19 at 2:21
  • Thanks! Yes, but those aren't the kind of diagrams I want. I need this other kind to help my students easily grasp the sentence syntax. – p.lugan Feb 25 '19 at 2:28
11

How about this?

\documentclass{article}
\usepackage[edges]{forest}
\forestset{students/.style={folder,
grow'=0,edge = {semithick},
edge path'={(!u.south-|.south west) |- (.south east)},
anchor=west,l sep=2.5em,s sep=0em}}
\usepackage{adjustbox}
\begin{document}
\begin{tabular}{lll}
\begin{adjustbox}{valign=T}
\begin{forest}
for tree={students}
[The man
 [big]
 [who lept
  [nimbly]
  [over the wall]
 ]
]
\end{forest}\end{adjustbox}&
\begin{adjustbox}{valign=T}\begin{forest}
for tree={students}
[sends 
 [always]
 [to mother
  [his]
 ] 
 [because he loves her
  [truly,xshift=3em]] 
]
\end{forest}\end{adjustbox}&
\begin{adjustbox}{valign=T}\begin{forest}
for tree={students}
[flowers
 [expansive]
]
\end{forest}
\end{adjustbox}
\end{tabular}
\end{document}

enter image description here

In this update, I added the second tree for illustration and packed all the definitions in a style that you can recycle, and which allows you to make changes globally. The relative vertical alignment is adapted from this nice answer.

| improve this answer | |
  • That's great! But is there a way of reducing the vertical space of the nodes? – p.lugan Feb 25 '19 at 2:44
  • @p.lugan Of course/ Just add s sep=0em after l sep=2.5em. – user121799 Feb 25 '19 at 2:45
  • Perfect. Just a side question: how can I manage to learn to do that by myself? The PGF/TikZ manual is simple overwhelming! – p.lugan Feb 25 '19 at 2:48
  • @p.lugan For this you may want to look at the forest manual first. (I will add an update. The most important thing there, apart from forest, will be this post.) – user121799 Feb 25 '19 at 2:52

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.