summaryrefslogtreecommitdiff
path: root/usergrps/uktug/baskervi/6_2/spqr/pstrix2.tex
blob: c8cbfd096e4cb7fcd1e25b06325cbbc47570cb27 (plain)
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
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
\documentclass{baskerv}
\usepackage[T1]{fontenc}
\usepackage{spqr}
\begin{document}
\def\CurrentPackages{spqr,pstcol}
\newcounter{myN}
\setlongtables
\author[Sebastian Rahtz]{Sebastian Rahtz\\Elsevier Science Ltd\\
Email: \texttt{s.rahtz@elsevier.co.uk}}
\title{An introduction to PSTricks, part 2}
\begin{Article}
\section{Preface}
In the first part of this description of \PST, we looked at 
the basic concepts of the package, a series of low-level building
blocks, and the useful commands for dealing with text and the third
dimension. Now it is time to look at the higher-level packages built
in \PST, for drawing trees and graphs. There are a wide variety of
applications, as I hope the examples show. This part of the package
is, unfortunately, extremely rich, and readers should not be surprised
if they find the plethora of new commands rather confusing.

%---------------------------
\section{Nodes and their connections, and trees}
\PST\ offers sophisticated macros for setting up named nodes
and joining them together in complicated ways, complete with labels.

The nodes can be created in three ways:
\begin{enumerate}
\item By placing them at arbitrary coordinates
\item By placing them on a regular grid or matrix
\item By using higher-level tree macros
\end{enumerate}
The sort of effect we will create is like this:

\begin{GridPSExample}(0,0)(5,5)
\rput(1,1){\rnode{A}{Dog}}
\rput(2,4){\rnode{B}{Cat}}
\rput(4,2){\rnode{C}{Mouse}}
\ncline{A}{B}
\nccurve[linestyle=dotted]{A}{B}
\ncarc[linestyle=dashed]{A}{B}
\end{GridPSExample}

Every node is given a symbolic name, which is used for
node connectors (lines, curves and so on), and for node labels. The
fact that nodes can occur \emph{anywhere} (such as in running text),
makes it possible to use them for surprising effects like linking two
words \rnode{n1}{one} to \rnode{n2}{another}\nccurve{n1}{n2}. When
considering connectors, we have to distinguish between the position of
the node they are pointing \emph{towards} (the node reference point),
and the actual extent of the connector. Most node creators have an
invisible box around them, which determines the end of connector lines.
We will first list all the commands, and then give practical examples.

Table~\ref{PSTnode} lists all the node creation commands and node
connector commands, Table~\ref{PSTnodelab} lists the commands to label
connectors and nodes, and Table~\ref{PSTnodeparm} lists the extra
graphical parameters which apply to node connectors.

\end{multicols}
\begin{longtable}{lH{8.5cm}}
\caption{\protect\PST\ node drawing commands\label{PSTnode}}\\
\hline
\endfirsthead
\protect\PST\ node drawing commands \emph{cont.}\\
\hline
\endhead
\multicolumn{2}{l}{\bfseries\itshape Node creators}
\\
\PSTCom  \rnode`[refpoint]'{name}{text}
& create a node called \emph{name}, consisting of \emph{text};
connectors point to the \emph{refpoint}
\\
\PSTCom  \Rnode`\c~'{name}{text}
& the same as  \Lcs{rnode}, but the reference point is the middle of
the box's baseline, plus \c~{}
\\
\PSTCom  \pnode`\c~'{name}
& create a node at \c, which takes up no space
\\
\PSTComOpt  \cnode`\c~'{radius}{name}
& create a node consisting of circle of \emph{radius}
\\
\PSTComOpt  \Cnode`\c~'{name}
& create a node consisting of circle, using the
radius set by the \emph{radius} graphical parameter (it is sometimes
useful to set the radius for many circles)
\\
\PSTComOpt  \cnodeput`{angle}\c~'{name}{text}
\\
\PSTComOpt  \circlenode{name}{text}
& like \Lcs{pscirclebox}, but makes a node
\\
\PSTComOpt  \ovalnode{name}{text}
& like \Lcs{psovalbox}, but makes a node
\\
\PSTComOpt  \dianode{name}{text}
& like \Lcs{diabox}, but makes a node
\\
\PSTComOpt  \dotnode`\c~'{name}{text}
& like \Lcs{psdot}, but makes a node
\\
\PSTComOpt  \fnode`\c~'{name}{text}
& like \Lcs{psframe}, but makes a node
\\
\PSTComOpt  \trinode{name}{text}
& like \Lcs{tribox}, but makes a node
\\
[6pt]
\multicolumn{2}{l}{\bfseries\itshape Node connectors}
\\
\PSTComOpt  \ncline`{arrows}'{firstnode}{secondnode}
& straight line between nodes
\\
\PSTComOpt  \ncLine`{arrows}'{firstnode}{secondnode}
& straight line between nodes, but labels are placed as if the line
went right to the center of the nodes
\\
\PSTComOpt  \ncarc`{arrows}'{firstnode}{secondnode}
& arc between nodes; uses parameter \emph{arcangle}
\\
\PSTComOpt  \ncdiag`{arrows}'{firstnode}{secondnode}
& using the \emph{arm} and \emph{angle} parameters, `arms' start out
from each node and are then joined by a line; corner shape is
controlled by the \emph{linearc} parameter
\\
\PSTComOpt  \ncdiagg`{arrows}'{firstnode}{secondnode}
& as \Lcs{ncdiag}, but the second arm is not drawn
\\
\PSTComOpt  \ncbar`{arrows}'{firstnode}{secondnode}
& a line is drawn with  arms coming off at a right angle to the nodes,
at an angle of \emph{angleA}; the arm length is adjusted if necessary
\\
\PSTComOpt  \ncangle`{arrows}'{firstnode}{secondnode}
& draws a connect line \Lcs{ncdiag}, but the angle between arm A and
the connector line is forced to a right angle
\\
\PSTComOpt  \ncangles`{arrows}'{firstnode}{secondnode}
& like \Lcs{ncangle}, but arm A is joined to arm B by two line
segments that meet at a right angle
\\
\PSTComOpt  \ncloop`{arrows}'{firstnode}{secondnode}
& like \Lcs{ncangles} but 5 line segments are used, the second and
forth being \emph{loopsize} long
\\
\PSTComOpt  \nccurve`{arrows}'{firstnode}{secondnode}
& bezier curve between nodes, using the \emph{ncurv} parameters to
determine the control point positions
\\
\PSTComOpt \nccircle`{arrows}'{node}{radius}
& draws a circle or part circle of radius \emph{radius}
connecting the node to itself
\\[6pt]
\multicolumn{2}{l}{\bfseries\itshape Coil and zigzag node connectors}
\\
\PSTCom \nccoil`*[settings]{arrows}'{firstnode}{secondnode}
\\
\PSTCom \nczigzag`*[settings]{arrows}'{firstnode}{secondnode}
\end{longtable}

\begin{longtable}{llH{.4\textwidth}}
\caption{\protect\PST\ Graphical parameters for node connectors}
\label{PSTnodeparm}\\[1mm]
\emph{Parameter} & \emph{Default} & \emph{Explanation}\\
\hline
\endfirsthead
\protect\PST\ Graphical parameters for node connectors \emph{cont.}\\[1mm]
\emph{Parameter} & \emph{Default} & \emph{Explanation}\\
\hline
\endhead
\mbox{}\\
\endfoot
\Par{offset=dim} (0pt)
& the offset of the connection point to a node\\
\Par{nodesep=dim} (0pt) 
&the border around nodes at which connectors stop
\\
\Par{nodesepA=dim} (0pt) 
&the border around the first node
\\
\Par{nodesepB=dim} (0pt) 
&the border around the second node
 \\
\Par{arcangle=angle} (8) 
&in \Lcs{ncarc}, the angle between the arc and a straight line drawn between the nodes
 \\
\Par{angle=angle} (0) 
&the angle at which connectors hit the nodes
 \\
\Par{angleA=angle} (0) 
&the angle at which a connector hits the first node
 \\
\Par{angleB=angle} (0) 
&the angle at which a connector hits the second node
 \\
\Par{arm=dim} (10pt) 
&the length of the line segment where the connector joins the nodes
 \\
\Par{armA=dim} (10pt) 
&the length of the line segment where the connector joins the first node
 \\
\Par{armB=dim} (10pt) 
&the length of the line segment where the connector joins the second node
 \\
\Par{loopsize=dim} (1cm)
& the length of line segments for \Lcs{ncloop}
\\
\Par{ncurv=num} (0.67)
& the distance to Bezier control points in \Lcs{nccurve}; lower values
give tighter curves; the distance from the node to the first control
point is half \emph{ncurv} $\times$ the distance between the two end points\\
\Par{ncurvA=num} (0.67)
& as \emph{ncurv} but for first node only
\\
\Par{ncurvB=num} (0.67)
& as \emph{ncurv} but for second node only
\\
\Par{boxsize=dim} (0.4cm)
& half the width of the enclosing box of \Lcs{ncbox} and \Lcs{ncarcbox}
\\[6pt]
\multicolumn{3}{l}{\bfseries\itshape Parameters for node labels}\\
\Par{ref=ref} (c)
& sets the reference point for labels\\
\Par{nrot=rot} (0)
& the rotation of label text; if the angle is preceded by :, it is
measured with respect to the connector line; the letter abbreviations
we have already seen are available, so :U is commonly used to
align text on the connector line\\
\Par{npos=num} ()
& the position along the length of the connector line where a label is
placed; each connector line has one or more segments, and the value of
\emph{npos}+1 determines the segment on which the label is set; the
default values for this parameter are given in the \protect\PST\
manual, but can also be seen in the examples below\\
\Par{shortput=none/nab/tablr/tab} (none)
& determines whether short codes are available for labelling
connectors; see \pageref{shortput}.\\
\Par{tpos=num} (0.5)
& the proportion of the distance between nodes at which labels are
placed on a connector\\
\Par{mnode=type} (R)
& (for matrices) the default node type; possibilities are
R (\Lcs{Rnode}), r (\Lcs{rnode}), C (\Lcs{Cnode}), f (\Lcs{fnode}), p
(\Lcs{pnode}), circle (\Lcs{circlenode}), oval (\Lcs{ovalnode}), dia
(\Lcs{dianode}), tri (\Lcs{trinode}), dot (\Lcs{dotnote}), and none\\
\Par{emnode=type} (none)
& (for matrices) the type of node created for empty cells in a matrix\\
\Par{name=name} ()
& (for matrices) the name of a node; parameters like this can set in
square brackets in the cell\\
\Par{nodealign=true/false} (false)
& (for matrices) whether baselines of nodes pass through the centre of
nodes\\
\Par{mcol=l/r/c} (c)
& (for matrices) the alignment of a node within a matrix cell\\
\Par{mnodesize=dim} (-1pt)
& (for matrices) is positive, nodes are forced to be this size\\
\Par{rowsep=dim} (1.5cm) 
& (for matrices) the gap between rows \\
\Par{colsep=dim} (1.5cm) 
& (for matrices) the gap between columns \\
\end{longtable}

\begin{longtable}{lH{10cm}}
\caption{\protect\PST\ node connection 
 labelling commands}\label{PSTnodelab}\\
\hline
\endfirsthead
\protect\PST\ node connection labelling commands \emph{cont.}\\
\hline
\endhead
\multicolumn{2}{l}{\bfseries\itshape Labelling based on connector length}\\
\PSTComOpt \ncput {something}
& place \emph{something} on the connector line\\
\PSTComOpt \naput {something}
& place \emph{something} above the connector line\\
\PSTComOpt \nbput {something}
& place \emph{something} under the connector line\\[6pt]
\multicolumn{2}{l}{\bfseries\itshape Labelling based on distance
between nodes}\\
\PSTComOpt \tvput {something}
& working on the vertical distance between nodes, place \emph{something} in the middle of the line\\
\PSTComOpt \tlput {something}
& working on the vertical distance between nodes, place \emph{something}
to the left of the line\\
\PSTComOpt \trput {something}
& working on the vertical distance between nodes,
place \emph{something} to the right of the line\\
\PSTComOpt \thput{something}
& working on the horizontal distance between nodes, 
place \emph{something} in the middle of the line\\
\PSTComOpt \taput{something}
& working on the horizontal distance between nodes, 
place \emph{something} above the line\\
\PSTComOpt \tbput{something}
& working on the horizontal distance between nodes, 
place \emph{something} below the line\\[6pt]
\multicolumn{2}{l}{\bfseries\itshape Labelling nodes}\\
\PSTCom`[par]'{angle}{name}{something}
& place \emph{something} next to the node, at a distance of 
\emph{nodesep}, in the direction \emph{angle} from the centre of the node
\end{longtable}
\begin{multicols}{2}
\begin{table*}
\caption{\protect\PST\ drawing commands comparable to node connectors}
\label{PSTcondraw}
\begin{tabular}{l}
\PSTComOpt  \pcline`{arrows}'\c1\c2
\\
\PSTComOpt  \pccurve`{arrows}'\c1\c2
\\
\PSTComOpt  \pcarc`{arrows}'\c1\c2
\\
\PSTComOpt  \pcbar`{arrows}'\c1\c2
\\
\PSTComOpt  \pcdiag`{arrows}'\c1\c2
\\
\PSTComOpt  \pcangle`{arrows}'\c1\c2
\\
\PSTComOpt  \pcloop`{arrows}'\c1\c2
\\
\PSTCom \pczigzag`*[settings]{arrows}'\c1\c2
\\
\PSTCom \pccoil`*[settings]{arrows}'\c1\c2
\end{tabular}
\end{table*}
There are several important concepts we need to bear in mind when
looking at the myriad of node and connector commands:
\begin{enumerate}
\item When joining two nodes with something like a curve, the
connectors comes in by default on the right hand side of the object
(at 0 degrees). If we have two boxes side by side, the \emph{angleB}
parameter has to be set to 180 if we want the connector to come into
the second box on its left side. This may seem cumbersome at first,
but it makes for a flexible system;
\item the connector labelling commands all place the label
some proportion of the way along the connector, but they distinguish
between the distance between nodes, and the length of the line. The
former situation applies to constructions like matrices, where we
want the label positions to be constant, regardless of the size of the
nodes.
\item The node connectors are not drawn directly in \TeX, but are done
at the PostScript level; this means that \TeX\ is not always quite
sure how much space will be taken up by the object. Particularly when
curving connectors are drawn, you might find that they protrude
outside the area allowed  by \TeX --- adjust by hand.
\end{enumerate}
\label{shortput}
Because labelling node connectors is a very common thing to do, a
short cut is provided to save all the \Lcs{naput} commands etc. If the
parameter \emph{shortput} is set to \texttt{nab}, the \verb|^| is used
instead of \Lcs{naput} and \verb|_| instead of \Lcs{nbput}. If it is
set to \texttt{tablr}, the \verb|^| stands for \Lcs{taput},
\verb|_| for \Lcs{tbput},
\verb|<| for \Lcs{tlput} and
\verb|>| for \Lcs{trput}.

If all this were not enough, all the node connectors can also be used as
ordinary drawing tools, by using the commands listed in
Table~\ref{PSTcondraw}, where the `pc' version corresponds to the `nc'
node connector.

Let us first demonstrate the  effects of these basic building blocks:
\end{multicols}
\begin{longtable}{l}
\begin{PSTInlineExample}(3,1)
\rput(.5,.5){\rnode{A}{Cat}}
\rput(2.5,.5){\rnode{B}{Dog}}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\rput(.5,.5){\Rnode{A}{Cat}}
\rput(2.5,.5){\Rnode{B}{Dog}}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\pnode(.5,.5){A}
\pnode(2.5,.5){B}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\cnode(.5,.5){.2}{A}
\cnode(2.5,.5){.2}{B}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\psset{radius=.3}
\Cnode(.5,.5){A}
\Cnode(2.5,.5){B}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\rput(.5,.5){\circlenode{A}{Cat}}
\rput(2.5,.5){\circlenode{B}{Dog}}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\rput(.5,.5){\ovalnode{A}{Cat}}
\rput(2.5,.5){\ovalnode{B}{Dog}}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\rput(.5,.5){\trinode{A}{Cat}}
\rput(2.5,.5){\trinode{B}{Dog}}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\dotnode(.5,.5){A}
\dotnode(2.5,.5){B}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\fnode(.5,.5){A}
\fnode(2.5,.5){B}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\rput(.5,.5){\dianode{A}{Cat}}
\rput(2.5,.5){\dianode{B}{Dog}}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,.5){\rnode{B}{\psframebox{Dog}}}
\ncline{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,2)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,1.5){\rnode{B}{\psframebox{Dog}}}
\nccurve[angleB=180]{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,.5){\rnode{B}{\psframebox{Dog}}}
\ncarc{->}{A}{B}
\ncarc{->}{B}{A}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,2)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,1.5){\rnode{B}{\psframebox{Dog}}}
\ncbar{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,2)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,1.5){\rnode{B}{\psframebox{Dog}}}
\ncdiag[angleB=180]{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,2)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,1.5){\rnode{B}{\psframebox{Dog}}}
\ncdiagg[angleB=180]{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,2)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,1.5){\rnode{B}{\psframebox{Dog}}}
\ncangle[angleB=180]{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,2)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,1.5){\rnode{B}{\psframebox{Dog}}}
\ncangles[angleB=180]{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,2)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,1.5){\rnode{B}{\psframebox{Dog}}}
\ncloop[loopsize=.25,angleB=180]{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,2)
\rput(1,.5){\rnode{A}{\psframebox{Cat}}}
\nccircle{->}{A}{.5}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,.5){\rnode{B}{\psframebox{Dog}}}
\psset{coilarm=.01,coilwidth=.3}
\nccoil{A}{B}
\end{PSTInlineExample}
\\
\begin{PSTInlineExample}(3,1)
\rput(.5,.5){\rnode{A}{\psframebox{Cat}}}
\rput(2.5,.5){\rnode{B}{\psframebox{Dog}}}
\psset{coilarm=.01,coilwidth=.3}
\nczigzag{A}{B}
\end{PSTInlineExample}
\\
\end{longtable}
\begin{multicols}{2}
The effect of node connectors is demonstrated in the
following, which uses the \Lcs{multido} macro (we will look at that in
the next article) to place objects at
regular intervals around a circle, and join them up
\end{multicols}
\begin{example*}
\newcount\CtA
\newcount\CtB
\newcommand{\Wheel}[3]{{%
\psset{unit=#2}
\pspicture(-1,-1)(1,1)
\SpecialCoor
\degrees[#1]
\multido{\ia=1+1}{#1}{%
  \CtA=\ia
  \advance\CtA by 1
  \CtB=#1
  \advance\CtB by -\ia
  \multido{\ib=\CtA+1}
     {\CtB}{#3(1;\ia)(1;\ib)}}
\multido{\i=1+1}{#1}{%
  \rput(1;\i){%
   \pscirclebox[fillstyle=solid,
       fillcolor=white]%
    {\footnotesize\i}}}
\endpspicture}}

\Wheel{3}{1.8}{\psline}
\Wheel{5}{1.8}{\psline}
\psset{arcangle=10}
\Wheel{12}{3}{\pcarc[linecolor=blue]}
\end{example*}
\begin{multicols}{2}
It should be clear that we can draw arbitrary diagrams, trees etc
simply by working out the coordinates of each node; however, in
practice, there are two higher-level environments for easier creation
of nodes --- matrices and trees.

\subsection{Matrices --- grid-based nodes}
The existing \LaTeX\ \Lenv{tabular} or AMS \LaTeX\ \Lenv{matrix} can be
used to place nodes, but \PST\ provides its own environment, 
\Lenv{psmatrix}. This is like an easy
form of table, since the number of columns does not have to be
specified --- we simply separate column items by \verb|&| and rows by
\verb|\\| as normal, and \PST\ makes each cell a node, named as
\emph{rownumber},\emph{columnumber}. Thus the first node in the first
row is named \texttt{1,1} and the third node in the fourth row is
\texttt{4,3}, and these are used by the node connectors.

\Lcs{psmatrix} has an optional parameter in which we can set
\emph{rowsep} and \emph{colsep}, determining the gap between
nodes. The parameter \emph{shortput} is set to \emph{tab} inside
\Lcs{psmatrix} by default, so we can adopt a quite succinct notation:

\begin{PSExample}(0,0)(2.5,5)
\begin{psmatrix}[rowsep=1.5cm]
&City&\\
{\tiny Shack} & House & {\Large Hotel} 
\psset{arrows=<<-}
\ncline{1,2}{2,1}<{a}
\ncline{1,2}{2,2}>{b}
\ncline{1,2}{2,3}>{b}
\psset{arrows=-,linestyle=dotted}
\ncline{2,1}{2,2}
\ncline{2,2}{2,3}
\end{psmatrix}
\end{PSExample}

Notice in this example that the shorthand `>' stands for \Lcs{trput},
which places labels according to the distance between node centres,
not the connection length, which allows for the difference in sizes
of nodes in the second row. Nodes can span multiple columns by using
the \Lcs{psspan} command at the end of the cell, with a parameter of
the number of columns to span.

A simple example of a square matrix can be created as follows:
\begin{example*}
\begin{psmatrix}
A & B \\
$\sqrt{\frac{x + y}{z}}$ & D 
\ncline{->}{1,1}{1,2}
\ncline{->}{1,2}{2,2}
\ncline{->}{2,2}{2,1}
\ncline{->}{2,1}{1,1}
\end{psmatrix}
\end{example*}
\noindent but by changing a few initial parameter settings, we can
present a `fancier' result, with nodes encircled, arrows on
connectors, and a better spacing. The connector labels are added with
the short-hand forms, which are those which are positioned in relation
to node centres. In the second version below, we redo the labels with
the label types which relate to line length, which in this case gives
a better result. The outer looping connector is an example of a
construct whose extent \TeX\ will probably guess incorrectly.
\begin{example*}
\psset{arrows=->,labelsep=3pt,
linecolor=gray,mnode=circle}
\begin{psmatrix}[rowsep=20pt,colsep=28pt]
A & B \\
$\sqrt{\frac{x + y}{z}}$ & D 
\psset{linestyle=dotted}
\ncline{1,1}{1,2}^{\emph{firstly}}
\ncline{1,2}{2,2}>{\emph{next}}
\ncline{2,2}{2,1}_{\emph{then}}
\ncline{2,1}{1,1}<{\emph{lastly}}
\end{psmatrix}
\end{example*}

\begin{example*}
\psset{arrows=->,labelsep=3pt,
linecolor=gray,mnode=circle}
\begin{psmatrix}[rowsep=20pt,colsep=28pt]
A & B \\
$\sqrt{\frac{x + y}{z}}$ & D 
\psset{linestyle=dotted}
\ncline{1,1}{1,2}\naput{\emph{firstly}}
\ncline{1,2}{2,2}\naput{\emph{next}}
\ncline{2,2}{2,1}\naput{\emph{then}}
\ncline{2,1}{1,1}\naput{\emph{lastly}}
\nccurve[ncurv=2,linestyle=solid,angleA=90]{1,1}{2,2}
\end{psmatrix}
\end{example*}

Matrices can be nested, and it is possible to link  nodes from two
different matrices, if the nodes are given explicit names. Each
\Lcs{psmatrix} wipes out the current set of \emph{row,column} names.

\begin{example*}
\psset{linearc=.2}
\begin{psmatrix}[rowsep=3pt,colsep=-10pt]
[name=A]\psframebox{requirements}\\
&[name=B]\psframebox{design}\\
&&[name=C]\psframebox{coding}\\
&&&[name=D]\psframebox{testing}\\
&&&&[name=E]\psframebox{operations}
\psset{linearc=0,arrows=->,armA=0pt,angleB=90}
\ncangle{A}{B}
\ncangle{B}{C}
\ncangle{C}{D}
\ncangle{D}{E}
\psset{angleB=-90,angleA=180}
\ncangle{B}{A}
\ncangle{C}{B}
\ncangle{D}{C}
\ncangle{E}{D}
\end{psmatrix}
\end{example*}

A normal low-level \PST\
command,  like \Lcs{framebox}, can be applied to a whole matrix.
We have to take some care in this example with alignment to make
the connecting line horizontal, so we place the single node on the
left in its own matrix. 
\end{multicols}
\begin{example*}
\psset{fillcolor=white,fillstyle=solid}
\def\Show#1{\psshadowbox{#1}}
\psset{arrows=->}
\begin{psmatrix}
  [mnode=r,ref=t,ref=t]
   \psframebox[linestyle=none,framesep=.75]{%
    \psset{ref=c}
    \begin{psmatrix}
    [name=A]\Show{Stakeholder}
    \end{psmatrix}
       } &
  [mnode=r,ref=t]
   \psframebox[fillstyle=solid,framesep=.75,fillcolor=gray]{%
  \psset{ref=c}
  \rule{1cm}{0pt}
  \begin{psmatrix}
  [name=B]\Show{Goal} &\Show{Criteria}\\
          \Show{Sub-goal} & \Show{Justification}
          \ncline{1,1}{1,2}
          \ncline{1,1}{2,2}
          \ncline{1,1}{2,1}\tlput{Strategy}
          \ncline{2,1}{2,2}
  \end{psmatrix}
  }
\ncline[angleB=-180]{A}{B}\naput[npos=.7]{Model}
\end{psmatrix}
\end{example*}
\begin{multicols}{2}
\subsection{Tree diagrams}
\PST\ has an extremely rich environment for drawing trees, which
allow for very complex structures and presentation. The available
commands are listed in Table~\ref{PSTtree} and the graphical
parameters which apply especially to these are listed in
Table~\ref{PSTtreeparms}. As one might expect, most other commands and
parameters  are also available, from both the generalized drawing, and
the node connectors and labels. Each of the node types described
earlier is turned into a `tree' node, and named by prefixing it with a
`T' and removing the `node' suffix.

\end{multicols}
\begin{small}
\begin{longtable}{llH{10cm}}
\caption{\protect\PST\ Graphical parameters for trees}
\label{PSTtreeparms}\\[1mm]
\emph{Parameter} & \emph{Default} & \emph{Explanation}\\
\hline
\endfirsthead
\protect\PST\ Graphical parameters for trees \emph{cont.}\\[1mm]
\emph{Parameter} & \emph{Default} & \emph{Explanation}\\
\hline
\endhead
\mbox{}\\
\endfoot
\Par{bbd=dim} ()
& set lower bounding box to \emph{dim}\\
\Par{bbh=dim} ()
& set upper bounding box to \emph{dim}\\
\Par{bbl=dim} ()
& set left bounding box to \emph{dim}\\
\Par{bbr=dim} ()
& set right bounding box to \emph{dim}\\
\Par{edge=command} (\ncline)
& the node connector used to join tree nodes\\
\Par{fansize=dim}   (1cm)       
&size of base for \Lcs{Tfan} tree node\\
\Par{levelsep=*dim} (2cm)
& the distance between successive levels in a tree; the * makes the dimension be \emph{in addition} to the size of the nodes (levels are normally a fixed distance apart)\\
\Par{showbbox=true/false} (false)
& draw a dotted frame showing the enclosing rectangle of trees\\
\Par{thislevelsep=*dim} ()
& like \emph{levelsep} but applies only to the current tree\\
\Par{thistreefit=tight/loose} ()
& like \emph{treefit} but applies only to the current tree\\
\Par{thistreenodesize=dim} ()
& like \emph{treenodesize} but applies only to the current tree\\
\Par{thistreesep=dim} ()
& like \emph{treesep} but applies only to the current tree\\
\Par{tndepth=dim} ()
& the minimum depth of tree node labels\\
\Par{tnheight=dim} ()
& the minimum height of tree node labels\\
\Par{tnpos=l/r/a/b} (b)
& the position of tree node labels relative to the node (left, right, 
above, below) \\
\Par{tnsep=dim} ()
& the gap between tree node labels and the node (by default the same as 
\emph{labelsep} \\
\Par{treefit=tight/loose} (tight)
& if tight, \emph{treesep} is the minimum distance between nodes on any level; if loose, \emph{treesep} is the distance between the enclosing 
bounding boxes of subtrees\\
\Par{treeflip=true/false} (false)
& does a mirror image of the free, flipping the nodes\\
\Par{treemode=R/L/U/D} (D)
& the direction of tree growth (right, left, up and down)\\
\Par{treenodes=dim} ($-$1pt)
& if positive, this sets a fixed size for tree nodes, regardless of content\\
\Par{treesep=dim} (0.75cm)
& the distance between successive nodes in a tree\\
\Par{xbbd=dim} ()
& increase lower bounding box by \emph{dim}\\
\Par{xbbh=dim} ()
& increase upper bounding box by \emph{dim}\\
\Par{xbbl=dim} ()
& increase left bounding box by \emph{dim}\\
\Par{xbbr=dim} ()
& increase right bounding box by \emph{dim}\\
\end{longtable}
\end{small}

\begin{small}
\begin{longtable}{lH{.5\textwidth}}
\caption{\protect\PST\ tree drawing commands\label{PSTtree}}\\
\hline
\endfirsthead
\multicolumn{2}{l}{\protect\PST\ tree drawing commands \emph{cont.}}\\
\hline
\endhead
\PSTCom \PStree{node}{subtrees}
& draws a node and subtrees connected to it\\
\PSTCom \PSTree{rootnode} subtrees 
%\endpsTree
& an `environment' form of \Lcs{psTree}\\
\PSTCom \Tn
& null tree node \\
\PSTCom \tspace{dim}
& leave gap of \emph{dim} before next level\\
\PSTComOpt \TC
& tree node like \Lcs{Cnode} node\\
\PSTComOpt \TR{something}
& tree node like \Lcs{Rnode} node\\
\PSTComOpt \Tcircle{something}
& tree node like \Lcs{circlenode} node\\
\PSTComOpt \Tc{dim}
& tree node like \Lcs{cnode} node\\
\PSTComOpt \Tdia{something}
& tree node like \Lcs{dianode} node\\
\PSTComOpt \Tdot
& tree node like \Lcs{dotnode} node\\
\PSTComOpt \Tf
& tree node like \Lcs{fnode} node\\
\PSTComOpt \Tfan
& draws a triangle with a top corner of the predecessor node\\
\PSTComOpt \Toval{something}
& tree node like \Lcs{ovalnode} node\\
\PSTComOpt \Tp
& tree node like \Lcs{pnode} node\\
\PSTComOpt \Tr{something}
& tree node like \Lcs{rnode} node\\
\PSTComOpt \Ttri{something}
& tree node like \Lcs{trinode} node\\
\PSTComOpt \skiplevel {nodes or subtrees}
& miss out entire levels in a particular subtree\\
\PSTComOpt \skiplevels{n} {nodes or subtrees} 
& skip \emph{n} levels\\
\end{longtable}
\end{small}

\begin{multicols}{2}
The fundamental concept in \PST\ trees is the \emph{nesting} of trees;
a simple tree  consists of a root, and one or more nodes:
\begin{example*}
\pstree{\TC}{\TC\TC}
\end{example*}
\noindent but each node can itself be a tree:
\begin{example*}
\pstree{\TC}{\pstree{\TC}{\TC \TC}
 \pstree{\TC}{\TC \TC}}
\end{example*}
This simple constructs allows very complicated structures to be
erected, as the examples below show.

The following tree is a version of that shown in the \emph{\LaTeX\ Companion},
section 10.5.2, which was drawn using the \Lpack{ecltree} package; the
ease of notation is roughly similar. As often in \LaTeX, the
readability depends a great deal on how the code is laid out.  The
only change to the defaults is to lessen the vertical space between
trees, and add some extra space around nodes.
\begin{example*}
\pstree[nodesep=2pt,
  levelsep=20pt]{\TR{grandfather}}
{
 \pstree{\TR{uncle}}{\TR{cousin}}
 \pstree{\TR{father}}
   {
   \pstree{\TR{brother}}{\TR{nephew}}
   \pstree{\TR{Me}}
     {
      \pstree{\TR{son}}{\TR{grandson}}
     }
   }
}
\end{example*}

If we now consider another tree drawing package described in
the \emph{\LaTeX\ Companion}, Vanroose's \Lpack{trees}, the example in section
10.2.3 is a little harder to reproduce. The skeleton is trivial:
\begin{example*}
\pstree{\Tdot}
{
\Tdot
\pstree{\Tdot}
 {
 \pstree{\Tdot}
  {
   \Tdot
   \Tdot
   \Tdot
  }
  \Tdot
 }
}
\end{example*}

\noindent but when  we come to add in all the node and connector labels, and 
change a few parameters to make the result nicer, the markup becomes a
little complex, though the quantity is roughly similar to that of Vanroose:

\begin{example*}
\psset{labelsep=2pt,tnpos=a,radius=2pt}
\pstree[treemode=R]{\TC*~{25}}
{
\TC*~{5}~[tnpos=r]{$L_a$}
\taput{$a$}
\pstree{\TC*~{20}\tbput{$b$}}
 {
 \pstree{\TC*~{15}\taput{$a$}}
  {
   \TC*~{7}~[tnpos=r]{$L_{baa}$}\taput{$a$}
   \TC*~{5}~[tnpos=r]{$L_{bab}$}\taput{$b$}
   \TC*~{3}~[tnpos=r]{$L_{bac}$}\tbput{$c$}
  }
  \TC*~{5}~[tnpos=r]{$L_{bb}$}
  \tbput{$b$}
 }
}
\end{example*}

The node connectors in a tree are created by running
the macro \Lcs{psedge} with the two nodes; the definition of
\Lcs{psedge} can be overridden explicitly by a redefinition, or by
using the \emph{edge} parameter. Here we redefine \Lcs{psedge} to be a
curve, arrange the angles (bearing in mind that the tree is to grow
upwards), and obtain a pleasing result. Note also the explicit links
between named nodes, as well as the regular connections.
\end{multicols}
\begin{example*}
\footnotesize
\def\psedge{\nccurve}
\newcommand{\Female}[2][]{\TR[#1]{\emph{#2}}}
\newcommand{\Male}[2][]{\TR[#1]{#2}}
\psset{nodesep=2pt,angleA=90,angleB=-90,unit=.6cm}
\pstree[treemode=U]{\Female{{\bfseries Matilde}}}{
 \pstree{\Male{Sebastian}}{
  \pstree{\Male[name=P]{Philip}}{\Male{Frederick}\Female{Ethel}}
  \pstree{\Female[name=W]{Mary}}{\Male{Lionel}\Female{Agnes}}}
 \pstree{\Female{Leonor}}{
  \pstree{\Male[name=R]{Ra\'ul}}{\Male{Joaquim}\Female{J\'ulia}}
  \pstree{\Female[name=A]{Am\'elia}}{\Male{Melo}\Female{Augusta}}}
}
\psset{doubleline=true,linestyle=dotted}
\ncline{P}{W}\nbput{1940}
\ncline{R}{A}\nbput{1950}
\end{example*}
\begin{multicols}{2}
We said earlier that \PST\ does not always work out the extent of
objects correctly, and this is illustrated by the connectors in the
following example. Turning on \emph{showbbox}, we can see that without
the use of \emph{xbbl} etc in the second incarnation, the bounding box
is not correct:
\begin{example*}
\psset{angleB=-90,arrows=->,nrot=:U}
\def\molesworth#1{%
 \pstree[#1]{\Tdia{ }}
 {
  \Tp[arrows=->,edge={\ncbar[angleA=180]}]
  \nbput{Gabbitas}
  {\psset{linestyle=dashed,arrows=-} \Tp }
  \Tp[arrows=->,edge={\ncbar}]
  \naput{Thring}
 }
}
\psset{showbbox=true}
\begin{tabular}{l}
\molesworth{}\\[10pt]
\molesworth{xbbl=1cm,xbbr=1cm}
\end{tabular}
\end{example*}

The technique  of redefining edges is also necessary if we want
right-angled joins, rather than straight lines. Again, we need to take
care of the \emph{angleA} and \emph{angleB}, and ensure that in this
left-right tree the nodes all line up on their left edges, using the
\emph{ref} parameter. If this is not done, the \Lcs{ncangle} edges
produce strange results.
\begin{example*}
\def\Item#1{\Tr[ref=l]{%
 \psframebox[linestyle=none]{#1}}}
\def\psedge{\ncangle}
\psset{xbbd=1.5cm,treemode=R,
  angleB=-180,angleA=0,levelsep=72pt}
\pstree{\Item{langs}}{%
  \Item{german}
  \pstree{\Item{greek}}{%
    \Item{hamilton-kelly}
    \pstree{\Item{levy}}{%
      \Item{doc}
      \Item{src}
       }
    }
  \Item{italian}
  \pstree{\Item{portuguese}}{ 
    \Item{hyphenation}
   }
  \pstree{\Item{turkish}}{%
    \Item{doc}
    \Item{hyphen}
    \Item{inputs}
    \Item{mf}
    \Item{misc}
   }
\Item{xettex}
}
\end{example*}

This allows us to remake the small family again, but this time with
nicer connectors:
\begin{example*}
\def\XX#1{%
 \Tr{\psframebox{\rule{0pt}{9pt}#1}}%
}
\def\psedge{\ncangle}
\psset{angleB=90,angleA=-90,
   levelsep=36pt,armB=14pt}
\pstree{\XX{grandmother}}
{%
\pstree{\XX{aunt}}{\XX{cousin}}
\pstree{\XX{mother}}
   {
 \pstree{\XX{sister}}{\XX{niece}}
 \pstree{\XX{Me}}
    {
    \pstree{\XX{daughter}}
    {\XX{granddaughter}}
  }
 }
}
\end{example*}
The node connectors are, of course, standard \PST\ objects, so they
obey all the normal parameters; here we draw the lower part of the
tree with dashed lines, and each node content is set in math mode.
\begin{example*}
\footnotesize
\psset{nodesep=2pt}
\def\XX#1#2{%
 \TR{\ensuremath{#1_{\mbox{#2}}}}%
}
\pstree[xbbr=1.5cm]{\XX{R}{AMSU}}
 {
  \XX{S}{RawData}
  \pstree{\XX{S}{combine}
          \trput{\ensuremath{\oplus}}
          \tlput{\ensuremath{\oplus}}}
   {
   \psset{linestyle=dashed}
   \XX{R}{Modes}
   \XX{R}{Normal}
   \XX{R}{Vertical}
   \XX{R}{Latched}
   \XX{R}{Tripped}
   }
  \XX{S}{GenerateData}
 }
\end{example*}

If we want to hang distinct-looking trees off one node,
the \emph{ncangle} connector, with some offsets, produces the right result.
 \begin{example*}
\psset{framearc=.2,levelsep=4cm,
  armB=1cm,angleB=-180}
\def\psedge{\ncangle}
\def\TreeBox#1{\Tr{\psframebox{#1}}}
\pstree[treemode=R]{\TreeBox{Monitor}}
{ 
 \psset{offsetA=4pt}
 \TreeBox{Attitude Generator}
 \naput[npos=2.5]{{\small init}}
 \nbput[npos=2.5]{{\small stop}}
 \psset{offsetA=-4pt}
 \TreeBox{Normal Generator}
}
\end{example*}

With simple connectors, we do not need to worry about the offsets or
angles; what this example shows is how nested trees can change direction:

\begin{example*}
\psset{arrows=->,framearc=.2}
\def\Treebox#1{%
 \Tr{\psframebox{#1}}
}
\pstree[treemode=R]
{\Treebox{A$\rightarrow$B}}{
\pstree{
   \Treebox{B$\rightarrow$C}
         }{
 \Treebox{A$\rightarrow$D}
\pstree[treemode=L]
 {\Treebox{B$\rightarrow$E}}
 {\Tn\TC[arrows=<-]}
      }
}
\end{example*}

Finally, let us not forget the simple empty node:
\begin{example*}
\pstree{\Tp}{
 \Tcircle{A}
 \Tcircle{B}
}
\end{example*}
\end{Article}
\end{document}