| 1 |
\documentclass{article} |
| 2 |
\usepackage{trees} |
| 3 |
\usepackage{a4} |
| 4 |
|
| 5 |
\title{{\tt trees.sty}: A Macro for Drawing Binary \\ |
| 6 |
or Ternary Trees} |
| 7 |
|
| 8 |
\author{Peter Vanroose \\ |
| 9 |
[email protected]} |
| 10 |
\date{18 april 1990} |
| 11 |
|
| 12 |
\begin{document} |
| 13 |
|
| 14 |
\maketitle |
| 15 |
|
| 16 |
The following macros let you draw a (binary or ternary) tree of any size. |
| 17 |
For each "internal node", you only have to specify which are the descending |
| 18 |
nodes, with a \verb|\branch| command (\verb|\tbranch| for ternary node.). |
| 19 |
To this end, nodes are given a label (only used internally!). These macros |
| 20 |
will give you some ideas on designing similar things for, e.g., |
| 21 |
digital circuits. |
| 22 |
|
| 23 |
Trees are constructed with labels on the branches (default 0 and 1), and |
| 24 |
with text (e.g., its name or value) on the nodes. The first parameter to |
| 25 |
\verb|\branch| (0, 1, 2 or 3) determines the steepness of the branches. |
| 26 |
|
| 27 |
Example: |
| 28 |
\small |
| 29 |
\begin{verbatim} |
| 30 |
\begin{picture}(100,100)(-50,10) |
| 31 |
\unitlength=2mm |
| 32 |
\branchlabels ABC % 012 is the default |
| 33 |
\root(2,10) 0. % root at absolute coordinate (2,10) |
| 34 |
% its (internally used) label is 0 |
| 35 |
% the space before the 0 is obligatory |
| 36 |
\branch2{16} 0:1,2. % node 0 (i.e., the root) has children 1 and 2 |
| 37 |
% the text "1.00" is written above it |
| 38 |
% space is optional, :,. are obligatory |
| 39 |
\leaf{4}{$u_1$} 1. % node 1 is a leaf |
| 40 |
% "0.45" written above, "$u_1$" to the right |
| 41 |
\branch2{12} 2:3,7. % branch to node 3 goes up, and has label A |
| 42 |
\tbranch2{9} 3:4,5,6. |
| 43 |
\leaf{4}{$u_3$}4. % the symbols 0--7 can be replaced by anything |
| 44 |
\leaf{3}{$u_4$}5. |
| 45 |
\leaf{2}{$u_5$}6. |
| 46 |
\leaf{3}{$u_2$} 7. |
| 47 |
\end{picture} |
| 48 |
\end{verbatim} |
| 49 |
\normalsize |
| 50 |
will typeset something like: |
| 51 |
\begin{flushleft} |
| 52 |
\begin{picture}(100,100)(-50,10) |
| 53 |
\unitlength=2mm |
| 54 |
\branchlabels ABC |
| 55 |
\root(2,10) 0. |
| 56 |
\branch2{16} 0:1,2. |
| 57 |
\leaf{4}{$u_1$} 1. |
| 58 |
\branch2{12} 2:3,7. |
| 59 |
\tbranch2{9} 3:4,5,6. |
| 60 |
\leaf{4}{$u_3$}4. |
| 61 |
\leaf{3}{$u_4$}5. |
| 62 |
\leaf{2}{$u_5$}6. |
| 63 |
\leaf{3}{$u_2$} 7. |
| 64 |
\end{picture} |
| 65 |
\end{flushleft} |
| 66 |
\end{document} |