Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}}
share|improve this question
    
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 Aug 14 '12 at 13:06
    
I try to set the radius, but it seems to not take any effect –  sweetyBaby Aug 14 '12 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 Aug 14 '12 at 13:16
    
got it, thanks~~ –  sweetyBaby Aug 14 '12 at 13:37
    
Possible Duplicate: TikZ automata: size of circle around nodes? –  Peter Grill Aug 14 '12 at 15:02
add comment

1 Answer

up vote 3 down vote accepted

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

share|improve this answer
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 Aug 14 '12 at 13:46
    
so do you know how to add words in the arrow that from "a->b" –  sweetyBaby Aug 14 '12 at 13:55
    
@Jake, thanks. What would be a good rule of thumb for setting up the values? –  hpesoj626 Aug 14 '12 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 Aug 14 '12 at 14:31
    
@hpesoj626 thanks, it works~~ –  sweetyBaby Aug 14 '12 at 14:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.