2

I want to draw a binary tree like this:

enter image description here

I have come up with the code below, but the size of the circle is too large. I tried to decrease the size, however, failed, can someone tell me how?

 \usetikzlibrary{shapes,arrows,positioning}
   \usepackage{wrapfig}
  \usepackage{graphicx}
   \resizebox{.4\textwidth}{!}{\begin{tikzpicture}[
block/.style = {circle, draw,
        text width=2em,align=center,radius=.05cm},
    line/.style = {draw,thick, -latex'},
    node distance=0.9cm and 0.4cm
    ]

    % Place nodes
    \node [block] (a) {a};
    \node [block, below left of=a,xshift=-1.0cm, yshift=-0.3cm] (b) {b};
    \node [block, below right of=a,xshift=1.0cm, yshift=-0.3cm] (c) {c};
% Draw edges
\path [line] (a) -- (b);
\path [line] (a) -- (c);

\end{tikzpicture}}
4
  • How did you try to decrease the size? You should change the value of text width in your block style. Depending on how small you want your circles to be, you might also need to set a smaller value for inner sep (the default is 2pt).
    – Jake
    Commented Aug 14, 2012 at 13:06
  • I try to set the radius, but it seems to not take any effect
    – sweetyBaby
    Commented Aug 14, 2012 at 13:12
  • radius is only used for \draw (0,0) circle [radius=...] commands, it doesn't have an effect on node sizes. Try altering text width and inner sep.
    – Jake
    Commented Aug 14, 2012 at 13:16
  • Possible Duplicate: TikZ automata: size of circle around nodes? Commented Aug 14, 2012 at 15:02

1 Answer 1

3

Following the suggestion in Jake's comments, I replaced radius=0.05cm by something like text width = 0.05cm. Below is your modified code.

\documentclass{minimal}


\usepackage{tikz}

\usetikzlibrary{shapes,arrows,positioning}
\usepackage{wrapfig}
\usepackage{graphicx}


\begin{document}

\resizebox{.4\textwidth}{!}{\begin{tikzpicture}[
block/.style = {circle, draw,
align=center,text width = 0.1cm, inner sep = 0.1cm},
line/.style = {draw,thick, -latex'},
node distance=0.9cm and 0.4cm
]
    % Place nodes
    \node [block] (a) {a};
    \node [block, below left of=a,xshift=-1.0cm, yshift=-0.3cm] (b) {b};
    \node [block, below right of=a,xshift=1.0cm, yshift=-0.3cm] (c) {c};
% Draw edges
\path [line] (a) -- (b);
\path [line] (a) -- (c);

\end{tikzpicture}}


\end{document}

You should get the following output.

enter image description here

4
  • 1
    If you set it to a value that small, you should just remove the text width parameter completely, then the circle size will always match the contents.
    – Jake
    Commented Aug 14, 2012 at 13:46
  • so do you know how to add words in the arrow that from "a->b"
    – sweetyBaby
    Commented Aug 14, 2012 at 13:55
  • @Jake, thanks. What would be a good rule of thumb for setting up the values?
    – hpesoj626
    Commented Aug 14, 2012 at 14:15
  • @sweetyBaby, perhaps a \path [line] (a) -- node [sloped, above] {From $a$ to $b$} (b) ;? Then try to increase your node distance.
    – hpesoj626
    Commented Aug 14, 2012 at 14:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .