0

I have this tree:

enter image description here

That was created with this code:

\begin{figure}[h]
        \centering
        \begin{tikzpicture}
            \node[circle,draw]{}
            child{
                node[circle,draw]{a}
            }
            child[missing]{};
        \end{tikzpicture}
    \end{figure}

How do I increase the size of the root circle so that, even when empty, it looks like the bottom circle? Or is there a better way to create these trees?

3 Answers 3

1

With use of the forest package:

\documentclass[margin=3mm]{standalone}
\usepackage{forest}

\begin{document}
    \begin{forest}
for tree = {circle,
            draw,
            minimum size=1.1em,
            inner sep=2pt,
            font=\small,
    l sep=9mm,
    s sep=6mm
            }
[
    [a]
    [, coordinate, no edge]
]   
    \end{forest}
\end{document}

enter image description here

4
  • is it possible to color the nodes?
    – L. WD
    Sep 20, 2020 at 0:41
  • @L.WD Yes. Tree nodes in forest are regular TikZ nodes. See the forest documentation for more information.
    – Alan Munn
    Sep 20, 2020 at 1:59
  • @L.WD, yes, it is possible. What you like to color? Node's' borders? Nodes' fill? Only particular node?
    – Zarko
    Sep 20, 2020 at 2:06
  • 1
    Fine! I got it! Thank you.
    – L. WD
    Sep 20, 2020 at 13:48
1

You can simply define the size of the tree nodes to have a minimum. Since it's likely that the majority of your nodes will also be drawn as circles, and you may have more than one tree that looks like this, it makes sense to create a global style for re-use including all of those parameters.

If you're drawing a lot of trees, I would strongly recommend switching to forest. The base TikZ tree drawing tools are really not very usable: their syntax is very clunky and they do no automatic node packing.

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\tikzset{my tree/.style={every node/.style={draw,circle,minimum size=1.5em}}}\begin{document}
        \begin{tikzpicture}[my tree]
            \node{}
            child{
                node{a}
            }
            child[missing]{};
        \end{tikzpicture}
\end{document}

enter image description here

3
  • I will use also istgame package :)
    – Sebastiano
    Sep 19, 2020 at 21:28
  • 1
    @Sebastiano istgame is a great package, but it's really designed for a very specific purpose, game theory games. But for trees in computer science or linguistics, forest is almost certainly more useful.
    – Alan Munn
    Sep 19, 2020 at 21:30
  • Thank you very much.
    – L. WD
    Sep 20, 2020 at 13:47
0

Welcome to the TeX.SE community. I will use, as a fast solution an hack, putting into \node[circle,draw]{...} a phantom character: \phantom{\small a}.

enter image description here

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

\begin{document}
\begin{figure}[h]
        \centering
        \begin{tikzpicture}
            \node[circle,draw]{\phantom{\small a}}
            child{
                node[circle,draw]{a}
            }
            child[missing]{};
        \end{tikzpicture}
    \end{figure}
\end{document}
2
  • 1
    Thank you! I ended up using it for another problem.
    – L. WD
    Sep 20, 2020 at 13:47
  • @L.WD I have write something very fast to solve your question. All the best.
    – Sebastiano
    Sep 20, 2020 at 19:00

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.