4

I'm translating a manual of syntax and they have some examples of non-valid structures. The first one I was able to reproduce, but not the second.

This is what I'm trying to reproduce:

enter image description here

My current code is the following:

\documentclass{article}
\usepackage{tikz-qtree}

\begin{document}

\begin{figure}[h]
\centering

\textbf{a}) \begin{tikzpicture}[level distance=30pt,sibling distance=5mm] 
\tikzset{every tree node/.style={align=center,anchor=base}}
\tikzset{level 1+/.style={level distance=2\baselineskip}}
\tikzset{frontier/.style={distance from root=6\baselineskip}}
\Tree [.a [.b ] [.c ] ]
\begin{scope}[grow'=up,yshift=-1.7cm]
\Tree [.d [.b ] [.c ] ]
\end{scope}
\end{tikzpicture}\qquad

\textbf{b}) \begin{tikzpicture}[level distance=30pt,sibling distance=5mm] 
\Tree ??????????????????
\end{figure}

\end{document}
3

These do not necessarily look like trees, so I would not necessarily recommend to use a library specialized on trees for that.

\documentclass{article}
\usepackage{subfig}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}

\begin{figure}[h]
\centering
\subfloat[][]{\begin{tikzpicture}
\matrix (mat) [matrix of nodes,column sep=1em,row sep=1em,
 nodes={align=center,inner sep=2pt},ampersand replacement=\&]
 {
 \& a \& \\
 b \& \& c\\
 \& d \&\\
 };
 \draw (mat-2-1.north) -- (mat-1-2.south) -- (mat-2-3.north)
 (mat-2-1.south) -- (mat-3-2.north) -- (mat-2-3.south);
\end{tikzpicture}}
\qquad
\subfloat[][]{\begin{tikzpicture}
\matrix (mat) [matrix of nodes,column sep=1em,row sep=1em,
 nodes={align=center},ampersand replacement=\&]
 {
 \& a \& \\
 b \& \& c\\
 e \&  \& d\\
 };
 \draw (mat-2-1.north) -- (mat-1-2.south) -- (mat-2-3.north)
 (mat-2-1) -- (mat-3-3) (mat-2-3) -- (mat-3-1);
\end{tikzpicture}}
\end{figure}
\end{document}

enter image description here

3

Even though these are not trees, you can still get the effect with tikz-qtree if you want. Here's how. I don't necessarily recommend this, but for a one-off example it works fine. I've used a slightly different method for the first tree; your method of joining two trees using scope is probably simpler for that case.

\documentclass{article}
\usepackage{tikz-qtree,tikz-qtree-compat}
\begin{document}
\begin{tikzpicture}
[every tree node/.style={align=center,anchor=base}]
\Tree [.a [.\node(b) {\strut b}; ] \edge[draw=none]; [.\node(x) {};  ] [.\node(c) {\strut c}; ]]
\node (d) [below of=x] {d};
\draw (d.north) -- (b.south);
\draw (d.north) -- (c.south);
\end{tikzpicture}

\bigskip
\begin{tikzpicture}
[every tree node/.style={align=center,anchor=base},sibling distance=.5cm]
\Tree [.a [.\node(b) {\strut b}; \edge[draw=none]; [.\node(e) {\strut e}; ]]  [.\node(c) {\strut c}; \edge[draw=none]; [.\node(d){\strut d}; ]]]
\draw (e.north) -- (c.south);
\draw (d.north) -- (b.south);
\end{tikzpicture}

\end{document}

output of code

2

An alternative to marmot's nice answer:

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\begin{document}
\begin{figure}
    \centering
    \begin{subfigure}[t]{0.5\textwidth}
        \centering
        \begin{tikzpicture}[y=1.5cm]
            \node (a) at (0,0) {a};
            \node (b) at (-1,-1) {b};
            \node (c) at (1,-1) {c};
            \node (d) at (0,-2) {d};
            \draw (b.north)--(a.south)--(c.north);
            \draw (b.south)--(d.north)--(c.south);
        \end{tikzpicture}  
        \caption{}
    \end{subfigure}%
    \begin{subfigure}[t]{0.5\textwidth}
        \centering
        \begin{tikzpicture}[y=1.5cm]
            \node (a) at (0,0) {a};
            \node (b) at (-1,-1) {b};
            \node (c) at (1,-1) {c};
            \node (d) at (1,-2) {d};
            \node (e) at (-1,-2) {e};
            \draw (b.north)--(a.south)--(c.north);
            \draw (b.south)--(d.north);
            \draw (c.south)--(e.north);
        \end{tikzpicture}  
        \caption{}
    \end{subfigure}
\end{figure}
\end{document}

enter image description here

But I prefer this

\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\begin{document}
\begin{figure}
    \centering
    \begin{subfigure}[t]{0.5\textwidth}
        \centering
        \begin{tikzpicture}[y=1.5cm,every node/.style={circle,draw,minimum size=0.75cm}]
            \node (a) at (0,0) {a};
            \node (b) at (-1,-1) {b};
            \node (c) at (1,-1) {c};
            \node (d) at (0,-2) {d};
            \draw (b)--(a)--(c)--(d)--(b);
        \end{tikzpicture}  
        \caption{}
    \end{subfigure}%
    \begin{subfigure}[t]{0.5\textwidth}
        \centering
        \begin{tikzpicture}[y=1.5cm,every node/.style={circle,draw,minimum size=0.75cm}]
            \node (a) at (0,0) {a};
            \node (b) at (-1,-1) {b};
            \node (c) at (1,-1) {c};
            \node (d) at (1,-2) {d};
            \node (e) at (-1,-2) {e};
            \draw (d)--(b)--(a)--(c)--(e);
        \end{tikzpicture}  
        \caption{}
    \end{subfigure}
\end{figure}
\end{document}

enter image description here

1

Another alternative reproducing the figure using tikz-cd package. Using column sep= ... or row sep= ..., you could change the configuration of the tree.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}[column sep= 1cm]
& a \arrow[ld, no head] \arrow[rd, no head] & & & a \arrow[ld, no head] \arrow[rd, no head] & \\
b \arrow[rd, no head] & & c \arrow[ld, no head] & b \arrow[rrd, no head] &  & c \\
 & d &  & e \arrow[rru, no head] & & d
\end{tikzcd}
\end{document}

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.