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? –  Feb 25 '19 at 02: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. – Pedro Lugan Feb 25 '19 at 02:28

1 Answers1

10

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.

  • That's great! But is there a way of reducing the vertical space of the nodes? – Pedro Lugan Feb 25 '19 at 02:44
  • @p.lugan Of course/ Just add s sep=0em after l sep=2.5em. –  Feb 25 '19 at 02:45
  • Perfect. Just a side question: how can I manage to learn to do that by myself? The PGF/TikZ manual is simple overwhelming! – Pedro Lugan Feb 25 '19 at 02: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.) –  Feb 25 '19 at 02:52