Created
June 14, 2022 15:12
-
-
Save FedericoTartarini/5b3374ae82e4b9c2a36e99ae29a1ab51 to your computer and use it in GitHub Desktop.
YouTube tutorial on how to draw diagrams (linguistic trees) using LaTeX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage{forest} | |
\begin{document} | |
\pgfmathsetseed{14285} | |
\begin{center} | |
\begin{forest} | |
random tree/.style n args={3}{% #1 = max levels, #2 = max children, #3 = max content | |
content/.pgfmath={random(0,#3)}, | |
if={#1>0}{repeat={random(0,#2)}{append={[,random tree={#1-1}{#2}{#3}]}}}{}}, | |
before typesetting nodes={for tree={draw,s sep=2pt,rotate={int(30*rand)},l+={5*rand}, | |
if={isodd(level())}{fill=green}{fill=yellow}}}, | |
important/.style={draw=red,line width=1.5pt,edge={red,line width=1.5pt}}, | |
before drawing tree={sort by=y, for nodewalk={min=tree,ancestors}{important,typeset node}} | |
[,random tree={9}{3}{100}] | |
\end{forest} | |
\end{center} | |
\section{Basic example} | |
\begin{forest} | |
[1 | |
[2[6]] | |
[3 | |
[4] | |
[5] | |
] | |
] | |
\end{forest} | |
\begin{forest} | |
[1[ciao[3][hello user]][2]] | |
\end{forest} | |
\section{Children align} | |
\begin{forest} | |
[\LaTeX\ numerals, calign=first | |
[arabic[1][2][3][4]] | |
[roman[i][ii][iii][iv]] | |
[alph[a][b][c][d]] | |
] | |
\end{forest} | |
\section{For tree} | |
\begin{center} | |
\begin{forest} | |
[\LaTeX\ numerals, | |
for tree={calign=first} | |
[arabic[1][2][3][4]] | |
[roman[i][ii][iii][iv]] | |
[alph[a][b][c][d]] | |
] | |
\end{forest} | |
\end{center} | |
\section{Tier} | |
\begin{forest} | |
[VP, | |
[DP[John,tier=word]] | |
[V’ | |
[V[sent,tier=word]] | |
[DP[Mary,tier=word]] | |
[DP[D[a,tier=word]][NP[letter,tier=word]]] | |
] | |
] | |
\end{forest} | |
\section{tikz} | |
\begin{forest} | |
[123,circle,draw=red,line width=1.5pt,fill=yellow | |
[DP,draw][V’[V][DP]] | |
] | |
\end{forest} | |
\section{Conditional} | |
\begin{forest} | |
where n children=1{tier=word}{} | |
[VP | |
[DP[John]] | |
[V’ | |
[V[sent]] | |
[DP[Mary]] | |
[DP[D[a]][NP[letter]]] | |
] | |
] | |
\end{forest} | |
\section{Decoration} | |
\begin{forest} | |
[CP | |
[DP,name=item 1] | |
[\dots | |
[,phantom] | |
% [VP | |
% [DP] | |
% [V’ | |
% [V] | |
[DP,draw] | |
{ | |
\draw[->,dotted] () to[out=south west,in=south] (item 1); | |
\draw[<-,red] (.south east)--++(0em,-4ex)--++(-2em,0pt) | |
node[anchor=east,align=center]{Comment}; | |
} | |
]] | |
% ]] | |
\end{forest} | |
\section{Horizontal} | |
\begin{forest} | |
for tree={grow'=0} | |
[{text} | |
[1[Federico][Test]] | |
[2] | |
[3]] | |
\end{forest} | |
\\ | |
\begin{forest} | |
[1 | |
[2[6][7]] | |
[3,grow'=0 | |
[4] | |
[5] | |
] | |
] | |
\end{forest} | |
\section{Preamble} | |
\forestset{ | |
default preamble={ | |
font=\Huge, | |
for tree={circle,draw} | |
} | |
} | |
\begin{forest} [A[B][C]] \end{forest} | |
\begin{forest} red [D[E][F]] \end{forest} | |
\begin{forest} for tree={dotted} [G[H][I]] \end{forest} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment