6

I am a tikz novice. I wanted to draw a graph of a directed set and I managed to do so by putting code from online examples together, without much of an understanding what is going on. Now I would like to make some improvements, for which I didn't find examples (that could be integrated with my code).

My code so far:

\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{main node/.style={circle,draw}}
...
\begin{tikzpicture}
\node[main node] (B) {};
\node[main node] (a) [above left = 1 cm and 1cm of B] {$\alpha$};
    \node[main node] (a1)  [above left = 1 cm and 1cm of a]  {};
    \node[main node] (a2)   [above right = 1 cm and 1cm of a] {};
    \node[main node] (g) [above right = 1cm and 1cm of B] {$\gamma$};
    \node[main node] (g1)   [above left = 1 cm and 1cm of g]{};
    \node[main node] (g2)   [above right = 1 cm and 1cm of g]{};
    \node[main node] (g3)   [above right = 1 cm and 1cm of g2]{};
\path[draw,thick]
    (B) edge node {} (a)
    (B) edge node {} (g)
    (a) edge node {} (a1)
    (a) edge node {} (a2)    
    (g) edge node {} (g1)
    (g) edge node {} (g2)
    (g2) edge node {} (g3);         
\end{tikzpicture}

My output so far: Graph

Improvements I would like to make:

1) I would like to indicate that the graph continues. For example, the upper right node and edge I would like to replace by three dashes in the direction of the current edge. Such "three dashes extensions" I would also like to add to the children of $\alpha$.

2) I would like to draw a rectangle around all descendants of $\alpha$, including the indicated extension from point 1). I would like to put a text on the top of this box saying $\geq\alpha$

3) I would like to have all circles the same size, which is automatically determined by the largest label.

EDIT:

I can partially solve 3) by using minimum size=1cm for the style of the nodes. However, this would require adjusting 1cm whenever labels, fonts, other sizes are changed

3

1 can be done by making the nodes invisible (omitting draw) and making the edges dashed.

2 can be done using the fit tikzlibrary.

3 is rather difficult, because you have to set the node size beforehand whereas you know the largest node only after all nodes have been processed. There are ways to address this, but it will be (much) easier to define an absolute size (as you suggest yourself) or, alternatively, to compute the maximum size from a user-supplied largest node (in MWE below).

Note: this solution is based on existing questions: e.g., Tikz - How to Draw Boxes Around Set of Nodes. Please make sure to do an extensive search before asking a new question. For your MWE please make sure it compiles, i.e., including the \documentclass, \begin{document} and without ....

MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\tikzset{main node/.style={circle,draw}}

\newcommand{\largest}{$\gamma$}
\newlength{\sizemax}
\setlength{\sizemax}{\maxof{\widthof{\largest}}{\totalheightof{\largest}}}
\tikzset{minimum size=\sizemax+10pt}

\begin{document}
\begin{tikzpicture}
\node[main node] (B) {};
\node[main node] (a) [above left = 1cm and 1cm of B] {$\alpha$};
    \node[main node] (a1)  [above left = 1cm and 1cm of a]  {};
    \node[main node] (a2)   [above right = 1cm and 1cm of a] {};
    \node (a1x)   [above left = 1cm and 1cm of a1]{};
    \node (a2x)   [above left = 1cm and 1cm of a2]{};
    \node[main node] (g) [above right = 1cm and 1cm of B] {$\gamma$};
    \node[main node] (g2)   [above right = 1cm and 1cm of g]{};
    \node (g3)   [above right = 1cm and 1cm of g2]{};
\path[draw,thick]
    (B) edge (a)
    (B) edge (g)
    (a) edge (a1)
    (a) edge (a2)    
    (g) edge (a2)
    (g) edge (g2)
    (g2) edge[dashed] (g3)
    (a1) edge[dashed] (a1x)
    (a2) edge[dashed] (a2x);
\node[draw,fit=(a) (a1) (a2) (a1x) (a2x)] (ad) {};
\node[above=0mm of ad] {$\geq\alpha$};
\end{tikzpicture}
\end{document}

Result:

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.