1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
|
%% $Id: pst-tree-doc.tex 133 2009-09-17 05:53:56Z herbert $
\documentclass[11pt,english,BCOR10mm,DIV12,bibliography=totoc,parskip=false,smallheadings
headexclude,footexclude,oneside]{pst-doc}
\usepackage[utf8]{inputenc}
\usepackage{pst-tree}
\let\pstTreeFV\fileversion
\lstset{pos=t,language=PSTricks,
morekeywords={psGammaDist,psChiIIDist,psTDist,psFDist,psBetaDist,psPlotImpl},basicstyle=\footnotesize\ttfamily}
%
\begin{document}
\title{\texttt{pst-tree}}
\subtitle{Nodes and Trees; v.\pstTreeFV}
\author{Timothy Van Zandt\\Herbert Vo\ss}
\docauthor{Herbert Vo\ss}
\date{\today}
\maketitle
\tableofcontents
\clearpage%
\begin{abstract}
The node and node connections are perfect tools for making trees, but
positioning the nodes using \Lcs{rput} would be rather tedious.\footnote{%
Unless you have a computer program that generates the coordinates.}
The file \nxLPack{pst-tree.tex}/\nxLPack{pstree.sty} contains a high-level interface for
making trees.
It should be noted that the correct result is not guaranteed with every \Lprog{dvips} driver.
This package was written for Rokicki's\index{Rokicki}
\Lprog{dvips} programme, which is practically part of every \TeX{}
distribution.
%\vfill
%Thanks to: Lars Kotthoff, Geoff Mercer
\end{abstract}
\clearpage
% ---------------------
\section{Overview}
The tree commands are
\begin{BDef}
\Lcs{pstree}\Largb{<root>}\Largb{<successors>}
\end{BDef}
\begin{BDef}
\begin{tabular}{@{}l@{\kern30pt}l}
\TeX\ version & \LaTeX\ version\\
\Lcs{psTree}\Largb{<root>} & \LBEG{psTree}\Largb{root}\\
\qquad<successors> & \qquad<successors> \\
\Lcs{endpsTree} & \LEND{psTree}
\end{tabular}
\end{BDef}
These do the same thing, but just have different syntax. \Lcs{psTree} is the ``long'' version.
These macros make a box that encloses all the nodes, and whose baseline passes
through the center of the root.
Most of the nodes has a variant for use within a tree and are called tree nodes (see Section~\ref{treenodes}).
Trees and tree nodes are called \emph{\Index{tree objects}}. The \Larg{root} of a tree
should be a single tree object, and the \Larg{successors} should be one or more
tree objects. Here is an example with only nodes:
\begin{LTXexample}[pos=l]
\pstree[radius=3pt]{\Toval{root}}{\TC* \TC* \TC* \TC*}
\end{LTXexample}
There is no difference between a terminal node and a root node, other than
their position in the \Lcs{pstree}\Largb{} command.
Here is an example where a tree is included in the list of successors, and
hence becomes \Index{subtree}:
\begin{LTXexample}[pos=l]
\pstree[radius=3pt]{\Tp}{%
\TC*
\pstree{\TC}{\TC* \TC*}
\TC*}
\end{LTXexample}
\section{Tree Nodes}\label{treenodes}
In each case, the name of the tree node is
formed by omitting "`node"' from the end of the name and adding "T" at the
beginning. For example, \Lcs{psovalnode} becomes \Lcs{Toval}. Here is the list of such
tree nodes:
\begin{BDef}
\LcsStar{Tp}\OptArgs\\
\LcsStar{Tc}\OptArgs\Largb{dim}\\
\LcsStar{TC}\OptArgs\\
\LcsStar{Tf}\OptArgs\\
\LcsStar{Tdot}\OptArgs\\
\LcsStar{Tr}\OptArgs\Largb{stuff}\\
\LcsStar{TR}\OptArgs\Largb{stuff}\\
\LcsStar{Tcircle}\OptArgs\Largb{stuff}\\
\LcsStar{TCircle}\OptArgs\Largb{stuff}\\
\LcsStar{Toval}\OptArgs\Largb{stuff}\\
\LcsStar{Tdia}\OptArgs\Largb{stuff}\\
\LcsStar{Ttri}\OptArgs\Largb{stuff}
\end{BDef}
The syntax of a tree node is the same as of its corresponding ``normal'' node,
except that:
\begin{itemize}
\item There is always an optional argument for setting graphics parameters,
even if the original node did not have one;
\item There is no argument for specifying the name of the node;
\item There is never a coordinate argument for positioning the node; and
\item To set the reference point with \Lcs{Tr}, set the \Lkeyword{ref} parameter.
\end{itemize}
Figure~\ref{allnodes} gives a reminder of what the nodes look like.
\begin{figure}[!htb]
\begin{LTXexample}
\small
\psset{armB=1cm, levelsep=3cm, treesep=-3mm, angleB=-90, angleA=90, nodesepA=3pt}
\def\s#1{#1~{\tt\string#1}}\def\b#1{#1{\tt\string#1}}\def\psedge#1#2{\ncangle{#2}{#1}}
\psTree[treenodesize=1cm]{\Toval{Tree nodes}}
\s\Tp\Tc{.5}~{\tt\string\Tc} \s\TC
\psTree[levelsep=4cm,armB=2cm]{\Tp[edge=\ncline]}
\b\Tcircle \s\Tdot
\TCircle[radius=1.2]{\tt\string\TCircle}
\Tn \b\Toval \b\Ttri \b\Tdia
\endpsTree
\s\Tf \b\Tr \b\TR
\endpsTree
\end{LTXexample}
\caption{The tree nodes.}\label{allnodes}
\end{figure}
The difference between \Lcs{Tr} and \Lcs{TR} (variants of \Lcs{rnode} and \Lcs{Rnode},
respectively) is important with trees. Usually, you want to use \Lcs{TR} with
vertical trees because the baselines of the text in the nodes line up
horizontally. For example:
\begin{LTXexample}[pos=l]
$
\pstree[nodesepB=3pt]{\Tcircle{X}}{%
\TR{\tilde{\tilde{X}}}
\TR{x}
\TR{y}}
$
\end{LTXexample}
Compare with this example, which uses \Lcs{Tr}:
\begin{LTXexample}[pos=l]
$
\pstree[nodesepB=3pt]{\Tcircle{X}}{%
\Tr{\tilde{\tilde{X}}}
\Tr{x}
\Tr{y}}
$
\end{LTXexample}
There is also a null tree node:
\begin{BDef}
\Lcs{Tn}
\end{BDef}
It is meant to be just a place holder. Look at the tree in Figure
page~\pageref{allnodes}. The bottom row has a node missing in the middle.
\Lcs{Tn}\Largb{} was used for this missing node.
There is also a special tree node that doesn't have a ``normal'' version and
that can't be used as the root node of a whole tree:
\begin{BDef}
\LcsStar{Tfan}\OptArgs
\end{BDef}
This draws a triangle whose base is \Lkeyword{fansize} %=\makeatletter\psk@fansize\makeatother
and whose opposite corner is the predecessor node, adjusted by the value of
\Lkeyword{nodesepA} and \Lkeyword{offsetA}.
For example:
\begin{LTXexample}[pos=l]
\pstree[dotstyle=oplus,dotsize=8pt,nodesep=2pt]{\Tcircle{11}}{%
\Tdot
\pstree{\Tfan}{\Tdot}
\pstree{\Tdot}{\Tfan[linestyle=dashed]}}
\end{LTXexample}
\section{Tree orientation}
Trees can grow down, up, right or left, depending on the \Lkeyword{treemode=}
\Lkeyval{D}, \Lkeyval{U}, \Lkeyval{R}, or \Lkeyval{L} parameter.
Here is what the previous example looks like when it grows to the right:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\pstree[dotstyle=oplus,dotsize=8pt,
nodesep=2pt,treemode=R]
{\Tcircle{11}}{%
\Tdot
\pstree{\Tfan}{\Tdot}
\pstree{\Tdot}{\Tfan[linestyle=dashed]}}
\end{LTXexample}
You can change the \Lkeyword{treemode} in the middle of the tree.
For example, here is a tree that grows up, and that has a subtree which grows
to the left:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\footnotesize
\pstree[treemode=U,dotstyle=otimes,dotsize=8pt,nodesep=2pt]
{\Tdot}{%
\pstree[treemode=L]{\Tdot}{\Tcircle{1} \Tcircle{2}}
\pstree{\Tdot}{\Tcircle{3} \Tcircle{4}}}
\end{LTXexample}
Since you can change a tree's orientation, it can make sense to include a tree
(<treeB>) as a root node (of <treeA>). This makes a single logical tree, whose
root is the root of <treeB>, and that has successors going off in different
directions, depending on whether they appear as a successor to <treeA> or to
<treeB>.
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\pstree{\pstree[treemode=L]{\Tcircle{root}}{\Tr{B}}}{%
\Tr{A1}
\Tr{A2}}
\end{LTXexample}
%%DG: to do
On a semi-related theme, note that any node that creates an LR-box can contain
a tree. However, nested trees of this kind are not related in any way to the
rest of the tree. Here is an example:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\psTree{\Tcircle{%
\pstree[treesep=0.4,levelsep=0.6,
nodesepB=-6pt]{\Tdot}{%
\TR{a} \TR{b}}}}
\TC
\TC
\endpsTree
\end{LTXexample}
When the tree grows up or down, the successors are lined up from left to right
in the order they appear in \Lcs{pstree}. When the tree grows to the left or
right, the successors are lined up from top to bottom. As an afterthought, you
might want to flip the order of the nodes. The keyword \Lkeyword{treeflip}=\true/\false
let's you do this. For example:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\footnotesize
\pstree[treemode=U,dotstyle=otimes,dotsize=8pt,
nodesep=2pt,treeflip=true]{\Tdot}{%
\pstree[treemode=R]{\Tdot}{\Tcircle{1} \Tcircle{2}}
\pstree{\Tdot}{\Tcircle{3} \Tcircle{4}}}
\end{LTXexample}
Note that I still have to go back and change the \Lkeyword{treemode} of the subtree
that used to grow to the left.
\section{The distance between successors}
The distance between successors is set by the key \Lkeyword{treesep}.
The rest of this section describes ways to fine-tune the spacing between
successors.
You can change the method for calculating the distance between subtrees by
setting the \Lkeyword{treefit}=\Lkeyval{tight}/\Lkeyval{loose}
parameter. Here are the two methods:
\begin{description}
\item[\Lkeyval{tight}] When \Lkeyset{treefit=tight}, which is the default, \Lkeyword{treesep} is
the minimum distance between each of the levels of the subtrees.
\item[\Lkeyval{loose}] When \Lkeyset{treefit=loose}, \Lkeyword{treesep} is the distance between the
subtrees' bounding boxes. Except when you have large intermediate nodes, the
effect is that the horizontal distance (or vertical distance, for horizontal
trees) between all the terminal nodes is the same (even when they are on
different levels).\footnote{%
When all the terminal nodes are on the same level, and the intermediate
nodes are not wider than the base of their corresponding \Index{subtree}s, then
there is no difference between the two methods.}
\end{description}
Compare:
\begin{center}
\tabcolsep=1cm
\begin{tabular}{cc}
\psset{radius=2pt}
\pstree{\TC*}{%
\TC
\pstree{\TC*}{%
\pstree{\Tc{3pt}}{\TC \TC}
\TC*}}
&
\psset{radius=2pt}
\pstree[treefit=loose]{\TC*}{%
\TC
\pstree{\TC*}{%
\pstree{\Tc{3pt}}{\TC \TC}
\TC*}}
\end{tabular}
\end{center}
With \Lkeyset{treefit=loose}, trees take up more space, but sometimes the structure
of the tree is emphasized.
%Another (orthogonal) way to highlight the structure of the tree is by setting
%\begin{Ex}
% \Par{xtreesep=dim}
%\end{Ex}
%to a positive value. The effect is that adjacent nodes with different parents
%are farther apart than adjacent nodes with the same parent.\footnote{%
%When \p{treefit=tight}, the minimum distance between levels other than the top
%of the subtrees is increased by \p{xtreesep}. When \p{treefit=loose}, the
%minimum distance between subtrees is increased by \p{xtreesep}}.
%This would have no effect in the previous two examples, but compare the
%spacing between the two subtrees in
%\begin{LTXexample}
% \psTree[radius=2pt,levelsep=1.5,xtreesep=.25cm] \TC* \\
% \pstree{\TC*}{\TC* \TC*}
% \pstree{\TC*}{\TC* \TC*}
% \endpsTree
%\end{LTXexample}
%with the spacing in
%\begin{LTXexample}
% \psTree[radius=2pt,levelsep=1.5] \TC* \\
% \pstree{\TC*}{\TC* \TC*}
% \pstree{\TC*}{\TC* \TC*}
% \endpsTree
%\end{LTXexample}
Sometimes you want the spacing between the centers of the nodes to be regular
even though the nodes have different sizes. If you set \Lkeyword{treenodesize}
to a non-negative value, then PSTricks sets the width (or height+depth for
vertical trees) to \Lkeyword{treenodesize}, \emph{for the purpose of calculating the
distance between successors}.
For example, ternary trees look nice when they are symmetric, as in the
following example:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\pstree[nodesepB=-8pt,treenodesize=.85]{\Tc{3pt}}{%
\TR{$x=y$}
\TR{$x_1=y_1$}
\TR{$x_{11}=y_{11}$}}%$
\end{LTXexample}
Compare with this example, where the spacing varies with the size of the
nodes:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\pstree[nodesepB=-8pt]{\Tc{3pt}}{%
\TR{$x=y$}
\TR{$x_1=y_1$}
\TR{$x_{11}=y_{11}$}}%$
\end{LTXexample}
Finally, if all else fails, you can adjust the distance between two successors
by inserting \Lcs{tspace}\Largb{length} between them:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\pstree{\Tc{3pt}}{%
\Tdia{foo}
\tspace{-0.5}
\Toval{and}
\Ttri{bar}}
\end{LTXexample}
\section{Spacing between the root and successors}
The distance between the center lines of the tree levels is \Lkeyword{levelsep}.
If you want the spacing between levels to vary with the size of the levels,
use the * convention. Then \Lkeyword{levelsep} is the distance between the bottom of
one level and the top of the next level (or between the sides of the two
levels, for horizontal trees).
Note: PSTricks has to write some information to your \Lext{aux} file if using
\LaTeX, or to \Lcs{jobname}.pst otherwise, in order to calculate the spacing.
You have to run your input file a few times before PSTricks gets the spacing
right.
%%DG: to do
%You are most likely to want to set \p{varlevelsep} to "true" in horizontal
trees. Compare the following example:
\begin{LTXexample}
\def\psedge#1#2{\ncdiagg[nodesep=3pt,angleA=180,armA=0]{#2}{#1}}
\pstree[treemode=R,levelsep=*1cm]{\Tr{George Alexander Kopf VII}}{%
\pstree{\Tr{Barry Santos}}{\Tr{James Kyle} \Tr{Ann Ada}}
\pstree{\Tr{Terri Maloney}}{\Tr{Uwe Kopf} \Tr{Vera Kan}}}
\end{LTXexample}
with this one, were the spacing between levels is fixed:
\begin{LTXexample}
\def\psedge#1#2{\ncdiagg[nodesep=3pt,angleA=180,armA=0]{#2}{#1}}
\pstree[treemode=R,levelsep=3cm]{\Tr{George Alexander Kopf VII}}{%
\pstree{\Tr{Barry Santos}}{\Tr{James Kyle} \Tr{Ann Ada}}
\pstree{\Tr{Terri Maloney}}{\Tr{Uwe Kopf} \Tr{Vera Kan}}}
\end{LTXexample}
%The center of the root node of a tree is positioned above the midpoint between
%the centers of the two outer successors. If you want the root to be positioned
%drectly above one of the successors, put the command
% \Mac \treecenter
%right \emph{after} that successor. For example:
%\begin{LTXexample}
% \def\myfan#1{\Tfan[fillstyle=solid,fillcolor=#1]\treecenter}%
% \pstree{\Tcircle{$x_2$}}{%
% \pstree{\Tcircle{$x_1$}}{%
% \pstree{\Tcircle{$x_0$}}{\myfan{black}}
% \myfan{gray}}
% \myfan{white}}
%\end{LTXexample}
%Here is another interesting example:
%\begin{example}
% \def\psedge{\ncangle[angleA=0,angleB=90]}
% \pstree[treesep=10pt]{\Tcircle[name=after]{$x_0$}}{%
% \Tfan[fillstyle=solid,fillcolor=black]
% \treecenter
% \pstree{\Tcircle{$x_1$}}{\Tfan[fillstyle=solid,fillcolor=darkgray]}
% \pstree{\Tcircle{$x_2$}}{\Tfan[fillstyle=solid,fillcolor=gray]}
% \pstree{\Tcircle{$x_3$}}{\Tfan[fillstyle=solid,fillcolor=lightgray]}
% \pstree{\Tcircle{$x_4$}}{\Tfan[fillstyle=solid,fillcolor=white]}}
%\end{example}
\section{Edges}
Right after you use a tree node command, \Lcs{pssucc} is equal to the name of the
node, and \Lcs{pspred} is equal to the name of the node's predecessor. Therefore,
you can draw a line between the node and its predecessor by inserting, for
example,
\begin{lstlisting}[style=syntax]
\ncline{\pspred}{\pssucc}
\end{lstlisting}
To save you the trouble of doing this for every node, each tree node executes
\begin{lstlisting}[style=syntax]
\psedge{\pspred}{\pssucc}
\end{lstlisting}
The default definition of \Lcs{psedge} is \Lcs{ncline}, but you can redefine it as
you please with \Lcs{def} or \LaTeX's \Lcs{renewcommand}.
For example, here I use \Lcs{ncdiag}, with \Lkeyword{armA}=0, to get all the node
connections to emanate from the same point in the predecessor. \LaTeX{} users can instead type:
\begin{lstlisting}[style=syntax]
\renewcommand{\psedge}{\ncdiag[armA=0,angleB=180,armB=1cm]}
\end{lstlisting}
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\def\psedge{\ncdiag[armA=0,angleB=180,armB=1cm]}
\pstree[treemode=R,levelsep=3.5cm,framesep=2pt]{\Tc{6pt}}{%
\small \Tcircle{K} \Tcircle{L} \Tcircle{M} \Tcircle{N}}
\end{LTXexample}
Here is an example with \Lcs{ncdiagg}. Note the use of a negative \Lkeyword{armA} value
so that the corners of the edges are vertically aligned, even though the nodes
have different sizes:
\begin{LTXexample}
$
\def\psedge#1#2{\ncdiagg[angleA=180,armA=1cm,nodesep=4pt]{#2}{#1}}
% Or: \renewcommand{\psedge}[2]{ ... }
\pstree[treemode=R, levelsep=5cm]{\Tc{3pt}}{%
\Tr{z_1\leq y} \Tr{z_1<y\leq z_2} \Tr{z_2<y\leq x} \Tr{x<y}
}
$
\end{LTXexample}
Another way to define \Lcs{psedge}\Largb{} is with the \Lkeyword{edge}
parameter. Be sure to enclose the value in braces "{}" if it contains commas
or other parameter delimiters. This gets messy if your command is long, and
you can't use arguments like in the preceding example, but for simple changes
it is useful. For example, if I want to switch between a few node connections
frequently, I might define a command for each node connection, and then use
the \Lkeyword{edge} parameter.
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\def\dedge{\ncline[linestyle=dashed]}
\pstree[treemode=U,radius=2pt]{\Tc{3pt}}{%
\TC*[edge=\dedge]
\pstree{\Tc{3pt}}{\TC*[edge=\dedge] \TC*}
\TC*}
\end{LTXexample}
You can also set \Lkeyset{edge=none} to suppress the node connection.
If you want to draw a node connection between two nodes that are not direct
predecessor and successor, you have to give the nodes a name that you can
refer to, using the \Lkeyword{name} parameter. For example, here I connect two nodes
on the same level:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\pstree[nodesep=3pt,radius=2pt]{\Toval{nature}}{%
\pstree{\Tc[name=top]{3pt}}{\TC* \TC*}
\pstree{\Tc[name=bot]{3pt}}{\TC* \TC*}}
\ncline[linestyle=dashed]{top}{bot}
\end{LTXexample}
We conclude with the more examples.
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\def\psedge{\nccurve[angleB=180, nodesepB=3pt]}
\pstree[treemode=R, treesep=1.5, levelsep=3.5]%
{\Toval{root}}{\Tr{X} \Tr{Y} \Tr{Z}}
\end{LTXexample}
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\pstree[nodesepB=3pt, arrows=->, xbbl=15pt,
xbbr=15pt, levelsep=2.5cm]{\Tdia{root}}{%
$
\TR[edge={\ncbar[angle=180]}]{x}
\TR{y}
\TR[edge=\ncbar]{z}
$}
\end{LTXexample}
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\psset{armB=1cm, levelsep=3cm, treesep=1cm,
angleB=-90, angleA=90, arrows=<-, nodesepA=3pt}
\def\psedge#1#2{\ncangle{#2}{#1}}
\pstree[radius=2pt]{\Ttri{root}}{\TC* \TC* \TC* \TC*}
\end{LTXexample}
\section{Edge and node labels}
Right after a node, an edge has typically been drawn, and you can attach
labels using \Lcs{ncput}, \Lcs{tlput}, etc.
With \Lcs{tlput}, \Lcs{trput}, \Lcs{taput}, and \Lcs{tbput}, you can align the labels
vertically or horizontally, just like the nodes. This can look nice, at least
if the slopes of the node connections are not too different.
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\pstree[radius=2pt]{\Tp}{%
\psset{tpos=.6}
\TC* \tlput{k}
\pstree{\Tc{3pt} \tlput[labelsep=3pt]{r}}{%
\TC* \tlput{j}
\TC* \trput{i}}
\TC* \trput{m}}
\end{LTXexample}
Within trees, the \Lkeyword{tpos} parameter measures this distance from the
predecessor to the successor, whatever the orientation of the true.
(Outside of trees it measures the distance from the top to bottom or left to
right nodes.)
PSTricks also sets \Lkeyset{shortput=tab} within trees. This is a special
\Lkeyword{shortput} option that should not be used outside of trees. It implements
the following abbreviations, which depend of the orientation of the true:
\begin{center}
\begin{tabular}{ccc}
& \multicolumn{2}{c}{Short for:}\\
\emph{Char.} & \emph{Vert.} & \emph{Horiz.}\\[2pt]
\textasciicircum & \Lcs{tlput} & \Lcs{taput} \\
\textunderscore & \Lcs{trput} & \Lcs{tbput}
\end{tabular}
\end{center}
(The scheme is reversed if \Lkeyset{treeflip=true}.)
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\psset{tpos=.6}
\pstree[treemode=R, thistreesep=1cm,
thislevelsep=3cm,radius=2pt]{\Tc{3pt}}{%
\pstree[treemode=U, xbbr=20pt]{\Tc{3pt}^{above}}{%
\TC*^{left}
\TC*_{right}}
\TC*^{above}
\TC*_{below}}
\end{LTXexample}
You can change the character abbreviations with
\begin{BDef}
\Lcs{MakeShortTab}\Largb{<char1>}\Largb{<char2>}
\end{BDef}
The \verb+\n*put+ commands can also give good results:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\psset{npos=.6,nrot=:U}
\pstree[treemode=R, thistreesep=1cm,
thislevelsep=3cm]{\Tc{3pt}}{%
\Tc{3pt}\naput{above}
\Tc*{2pt}\naput{above}
\Tc*{2pt}\nbput{below}}
\end{LTXexample}
You can put labels on the nodes using \Lcs{nput}. However, \Lcs{pstree} won't take
these labels into account when calculating the bounding boxes.
There is a special node label option for trees that does keep track of the
bounding boxes:
\begin{BDef}
\Lnotation{\texttildelow}\OptArg*{*}\OptArgs\Largb{stuff}
\end{BDef}
Call this a ``tree node label''.
Put a tree node label right after the node to which it applies, before any
node connection labels (but node connection labels, including the short forms,
can follow a tree node label). The label is positioned directly below the node
in vertical trees, and similarly in other trees. For example:
\begin{LTXexample}
\pstree[radius=2pt]{\Tc{3pt}\nput{45}{\pssucc}{root}}{%
\TC*~{$h$} \TC*~{$i$} \TC*~{$j$} \TC*~{$k$}}
\end{LTXexample}
Note that there is no ``long form'' for this tree node label. However, you can
change the single character used to delimit the label with
\begin{BDef}
\Lcs{MakeShortTnput}\Largb{<char1>}
\end{BDef}
If you find it confusing to use a single character, you can also use a command
sequence. E.g.,
\begin{lstlisting}[style=syntax]
\MakeShortTnput{\tnput}
\end{lstlisting}
You can have multiple labels, but each successive label is positioned relative
to the bounding box that includes the previous labels. Thus, the order in
which the labels are placed makes a difference, and not all combinations will
produce satisfactory results.
You will probably find that the tree node label works well for terminal nodes,
without your intervention. However, you can control the tree node labels be
setting several parameters.
To position the label on any side of the node ("l"eft, "r"ight, "a"bove or
"b"elow), set: \Lkeyword{tnpos}=\Lkeyval{l}/\Lkeyval{r}/\Lkeyval{a}/\Lkeyval{b}
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\psframebox{%
\pstree{\Tc{3pt}~[tnpos=a,tndepth=0pt,radius=4pt]{root}}{%
\TC*~[tnpos=l]{$h$}
\TC*~[tnpos=r]{$i$}}}
\end{LTXexample}
When you leave the argument empty, which is the default, PSTricks chooses the
label position is automatically.
To change the distance between the node and the label, set \Lkeyword{tnsep} to a dimension
When you leave the argument empty, which is the default, PSTricks uses the
value of \Lkeyword{labelsep}. When the value is negative, the distance is measured
from the center of the node.
When labels are positioned below a node, the label is given a minimum height
of \Lkeyword{tnheight}.
Thus, if you add labels to several nodes that are horizontally aligned, and if
either these nodes have the same depth or \Lkeyword{tnsep} is negative, and if the
height of each of the labels is no more than \Lkeyword{tnheight}, then the labels
will also be aligned by their baselines. The default is \nxLcs{ht}\Lcs{strutbox}, which
in most \TeX{} formats is the height of a typical line of text in the current
font. Note that the value of \Lkeyword{tnheight} is not evaluated until it is used.
The positioning is similar for labels that go below a node. The label is given
a minimum \emph{depth} of \Lkeyword{tndepth}.
For labels positioned above or below, the horizontal reference point of the
label, i.e., the point in the label directly above or below the center of the
node, is set by the \Lkeyword{href} parameter.
When labels are positioned on the left or right, the right or left edge of the
label is positioned distance \Lkeyword{tnsep} from the node. The vertical point that
is aligned with the center of the node is set by \Lkeyword{tnyref}.
When you leave this empty, \Lkeyword{vref} is used instead. Recall that \Lkeyword{vref}
gives the vertical \emph{distance} from the baseline. Otherwise, the
\Lkeyword{tnyref} parameter works like the \Lkeyword{yref} parameter, giving the fraction of
the distance from the bottom to the top of the label.
\section{Details}
PSTricks does a pretty good job of positioning the nodes and creating a box
whose size is close to the true bounding box of the tree. However, PSTricks
does not take into account the node connections or labels when calculating the
bounding boxes, except the tree node labels.
If, for this or other reasons, you want to fine tune the bounding box of the
nodes, you can set the following parameters to a dimension:
\begin{tabular}{@{}l l @{}}
\emph{name} & \emph{default}\\\hline
\Lkeyword{bbl} & 0pt\\
\Lkeyword{bbr}& 0pt\\
\Lkeyword{bbh}& 0pt\\
\Lkeyword{bbd}& 0pt\\
\Lkeyword{xbbl}& 0pt\\
\Lkeyword{xbbr}& 0pt\\
\Lkeyword{xbbh}& 0pt\\
\Lkeyword{xbbd}& 0pt
\end{tabular}
The "`x"' versions increase the bounding box by <dim>, and the others set the
bounding box to the dimension. There is one parameter for each direction from the
center of the node, \textbf{l}eft, \textbf{r}ight, \textbf{h}eight, and
\textbf{d}epth.
These parameters affect trees and nodes, and subtrees that switch directions,
but not subtrees that go in the same direction as their parent tree (such
subtrees have a profile rather than a bounding box, and should be adjusted by
changing the bounding boxes of the constituent nodes).
Save any fiddling with the bounding box until you are otherwise finished with
the tree.
You can see the bounding boxes by setting the \Lkeyword{showbbox}=\true/\false
parameter to \true. To see the bounding boxes of all the nodes in a tree, you
have to set this parameter before the tree.
In the following example, the labels stick out of the bounding box:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\psset{tpos=.6,showbbox=true}
\pstree[treemode=U]{\Tc{5pt}}{%
\TR{foo}^{left}
\TR{bar}_{right}}
\end{LTXexample}
Here is how we fix it:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\psset{tpos=.6,showbbox=true}
\pstree[treemode=U,xbbl=8pt,xbbr=14pt]{\Tc{5pt}}{%
\TR{foo}^{left}
\TR{bar}_{right}}
\end{LTXexample}
Now we can frame the tree:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\psframebox[fillstyle=solid,fillcolor=lightgray,framesep=14pt,
linearc=14pt,cornersize=absolute,linewidth=1.5pt]{%
\psset{tpos=.6,border=1pt,nodesepB=3pt}
\pstree[treemode=U,xbbl=8pt,xbbr=14pt]{%
\Tc[fillcolor=white,fillstyle=solid]{5pt}}{%
\TR*{foo}^{left}
\TR*{bar}_{right}}}
\end{LTXexample}
We would have gotten the same result by changing the bounding box of the two
terminal nodes.
To skip levels, use
\begin{BDef}
\LcsStar{skiplevel}\OptArgs\Largb{nodes or subtrees}\\[4pt]
\LcsStar{skiplevels}\OptArgs\Largb{int} \\
\qquad<nodes or subtrees> \\
\Lcs{endskiplevels}
\end{BDef}
These are kind of like subtrees, but with no root node.
\begin{LTXexample}
\pstree[treemode=R,levelsep=1.8,radius=2pt]{\Tc{3pt}}{%
\skiplevel{\Tfan}
\pstree{\Tc{3pt}}{%
\TC*
\skiplevels{2}
\pstree{\Tc{3pt}}{\TC* \TC*}
\TC*
\endskiplevels
\pstree{\Tc{3pt}}{\TC* \TC*}}}
\end{LTXexample}
The profile at the missing levels is the same as at the first non-missing
level. You can adjust this with the bounding box parameters. You get greatest
control if you use nested \Lcs{skiplevel} commands instead of \Lcs{skiplevels}.
\begin{LTXexample}
\large\psset{radius=6pt, dotsize=4pt}
\pstree[thislevelsep=0,edge=none,levelsep=2.5cm]{\Tn}{%
\pstree{\TR{Player 1}}{\pstree{\TR{Player 2}}{\TR{Player 3}}}
\psset{edge=\ncline}
\pstree{\pstree[treemode=R]{\TC}{\Tdot ~{(0,0,0)} ^{N}}}{%
\pstree{\TC[name=A] ^{L}}{%
\Tdot ~{(-10,10.-10)} ^{l}
\pstree{\TC[name=C] _{r}}{%
\Tdot ~{(3,8,-4)} ^{c}
\Tdot ~{(-8,3,4)} _{d}}}
\pstree{\TC[name=B] _{R}}{%
\Tdot ~{(10,-10.0)} ^{l}
\pstree{\TC[name=D]_{r}}{%
\Tdot ~{(4,8,-3)} ^{c}
\Tdot ~{(0,-5,0)} _{d}}}}}
\ncbox[linearc=.3,boxsize=.3,linestyle=dashed,nodesep=.4]{A}{B}
\ncarcbox[linearc=.3,boxsize=.3,linestyle=dashed,arcangle=25,nodesep=.4]{D}{C}
\end{LTXexample}
\section{The scope of parameter changes}
\Lkeyword{edge} is the only parameter which, when set in a tree node's parameter
argument, affects the drawing of the node connection (e.g., if you want to
change the \Lkeyword{nodesep}, your edge has to include the parameter change, or you
have to set it before the node).
As noted at the beginning of this section, parameter changes made with
\Lcs{pstree} affect all subtrees. However, there are variants of some of these
parameters for making local changes, i.e, changes that affects only the
current level: \Lkeyword{thistreesep}, \Lkeyword{thistreenodesize},
\Lkeyword{thistreefit}=\Lkeyval{tight}/\Lkeyval{loose}, and \Lkeyword{thislevelsep}.
For example:
\begin{LTXexample}[pos=l,width=0.4\linewidth]
\pstree[thislevelsep=.5cm,thistreesep=2cm,
radius=2pt]{\Tc*{3pt}}{%
\pstree{\TC*}{\TC* \TC*}
\pstree{\TC*}{\TC* \TC*}}
\end{LTXexample}
There are some things you may want set uniformly across a level in the tree,
such as the \Lkeyword{levelsep}. At level <n>, the command \nxLcs{pstreehook<roman(n)>}
(e.\,g., \Lcs{pstreehookii}) is executed, if it is defined (the root node of the
whole tree is level 0, the successor tree objects and the node connections
from the root node to these successors is level 1, etc.). In the following
example, the \Lkeyword{levelsep} is changed for level 2, without having to set the
\Lkeyword{thislevelsep} parameter for each of the three subtrees that make of
level 2:
\begin{LTXexample}
\[
\def\pstreehookiii{\psset{thislevelsep=3cm}}
\pstree[treemode=R,levelsep=1cm,radius=2pt]{\Tc{4pt}}{%
\pstree{\TC*}{%
\pstree{\TC*}{\Tr{X_1} \Tr{X_2}}
\pstree{\TC*}{\Tr{Y_1} \Tr{Y_2}}}
\pstree{\TC*}{%
\pstree{\TC*}{\Tr{K_1} \Tr{K_2}}
\pstree{\TC*}{\Tr{J_1} \Tr{J_2}}}}
\]
\end{LTXexample}
\clearpage
\section{List of all optional arguments for \nxLPack{pst-tree}}
The default value ist set when an optional argument is called without any value,
e.\,g. \Lcs{pstree}\Largs{levelsep} is the same as \Lcs{pstree}\Largs{levelsep=2cm}.
All boolean arguments are preset to \false.
\xkvview{family=pst-tree,columns={key,type,default}}
\nocite{*}
\bgroup
\raggedright
\bibliographystyle{plain}
\bibliography{\jobname}
\egroup
\printindex
\end{document}
|