Debian Codegraph @

texmf-dist/doc/generic/pst-tree/pst-tree-doc.tex

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