2

I am currently learning how to use Tikz in order to draw graphs. Since I am a beginner I can't seem to figure out how to draw the following graph:

enter image description here

What's puzzling me here is the shapes encircling the graph vertices as well as the alignment of text underneath those shapes.

Here is my code so far (it only generates L0 and L1):

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=2]
    \tikzset{vertex/.style={draw, circle, inner sep = 2pt, fill=black}}
    \node (v2) at (0,0.5) [vertex] {};
    \node (v3) at (.5,1) [vertex] {};
    \node (v5) at (.5, .5) [vertex] {};
    \node (v6) at (.5, 0) [vertex] {};
    \draw (v2) to (v3);
    \draw (v2) to (v5);
    \draw (v2) to (v6);
\end{tikzpicture}
\end{document}

Thanks in advance!

2
  • 1
    Welcome to TeX.SE! Can you please show us the code you have so far?
    – Mensch
    Nov 11, 2021 at 22:32
  • @Mensch I will add it but it is not much. Nov 11, 2021 at 22:37

1 Answer 1

4

Technically the code you provided is all you need. But if if you want to draw trees you may want to use the child {} command

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{nicefrac,xfrac}
\tikzset{vertex/.style={draw, circle, inner sep = 1pt, fill=black,}}
\begin{document}
\begin{tikzpicture}[grow=0,level 1/.style={sibling distance=3em},
    level 2/.style={sibling distance=2em},]
    \node[vertex] (z) {}
    child { node[vertex] (x){} 
        child { node[vertex] (y) {} }
        child { node[vertex] {} }
    }
    child { node[vertex] {} 
        child { node[vertex] (a) {} }
        child { node[vertex] (b) {} }
    }
    child {node[vertex] {} 
        child { node[vertex] {} }
        child { node[vertex] {} }
    };
%ellipse
\draw[violet] (0,0) ellipse (0.1cm and 0.5cm);
\draw[violet] (1.5,0) ellipse (0.25cm and 1.5cm);
\draw[violet] (3,0) ellipse (0.5cm and 2cm);

\node[vertex,right of=a, xshift=2cm] (c) {};
\node[vertex,right of=b, xshift=2cm] (d) {};

\draw[dotted] (c) -- (a);
\draw[dotted] (d) -- (b);
\path [bend right] (c) edge (d);

%labels
\node at (0,-3)  {$L_{0}$};
\node at (1.5,-3)  {$L_{1}$};
\node at (3,-3)  {$L_{2}$};
\node at (6,-3)  {$L_{\tfrac{K-1}{2}}$};

\end{tikzpicture}
\end{document}

enter image description here

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.