[Xy-pic] Help with trees?!

Wolfgang Drotschmann drotschm at fgan.de
Tue Mar 11 09:47:41 CET 2003

Hallo all!

>From time to time I use the Xy-pic package.  I think it's great stuff!

Among its goodies I found something to layout trees (e.g. for
directories) in a nice way (see [1] for details, and "tree.sty", taken
from [1], in the attachment of this mail).
Normally this tree thing works great.
But for trees with long lines, I mean, long entries for nodes, those
horizontal lines get too long.

This is a sketch of what I tried:

Study Package
    +-----WP 1000 ---> blablabla                   | <- right margin
    |                                              |
    +-----WP 2000 ---> blablablabla                |
    |           |                                  |
    |           `------------------- ST 2100 blubbblubbblubb
    :                                              |
    :                /\
                      `-- How can I reduce the length of this line?

So, the branch from "WP 2000" to "ST 2100" gets too long, and the leaf
is printed over the right margin.
The problem seems to be that the point where the line starts is the
middle of the whole inner node.

So, I'm looking for a way to shorten the branch line.  Sometimes, it
seems reasonable to define a constant length for this.
Or, alternatively, to define a starting point for this line.

I tried my best and looked up the Xy-pic user guide and ref man, but I'm
lost.  I assume I have to change the definition of the macro \branch or
maybe the macro \openaction (both in "tree.tex")... well, somehow...

Any clues?

Many thanks in advance!


[1] http://tug.org/applications/Xy-pic/soft/xypapers/tug97rose.ps
-------------- next part --------------

% tree.tex: Print \tree{ <tree> } as directory tree.

\typeout{Prettyprint a tree-like structure with help of Kris Rose and Xy-pic.}

% Use \Xy-pic. including ``stack empty'' primitive.
\input xy
{\catcode`\@=11 \global\let\sempty=\sempty@}

% Idioms.
\def\SP.{\futurelet\SP\relax}\SP. %

% <tree> parser.
\def\tree#1{\xy \beginaction \FN\parser#1\relax \endaction \endxy}
  \ifx\SP\next \expandafter\DN\space{\FN\parser}%
  \else\ifx\bgroup\next \DN##1{\textaction{##1}\FN\parser}%
  \else\ifx(\next       \DN({\openaction \FN\parser}%
  \else\ifx)\next       \DN){\closeaction\FN\parser}%
  \else\ifx\relax\next  \DN\relax{}%
  \else \DN{%
    \errmessage{<tree> build from (, ), and {text} only: not \meaning\next}}%
  \fi\fi\fi\fi\fi \next}

% Initial action: start fresh stack frame.
\def\beginaction{\POS @( }

% Interpretation action for {text}: typeset node and its branch!
\def\textaction#1{\node{#1}\if\sempty\else \branch \fi}
\def\branch{\ar @{-} `l/\jot s0+DC="s0" "s0" }

% Interpretation action for (: move back and down!
\def\openaction{\POS @+c +R+/r1em/ +/d\baselineskip/ }

% Interpretation action for ): move back below parent!
\def\closeaction{\if\sempty \errmessage{too many )s in <tree>}%
  \else \POS {;p+/r/:s0;p+/d/,x}@-c \fi}

% Final action: obliterate stack frame.
\def\endaction{\if\sempty\else \errmessage{missing )s in <tree>}\fi
  \POS @) }

% To have a box around a node, the following is defined:
\xyoption{frame}  % Use the frame extension!
  {\xy *+<2.0pt>\txt{#1}*\frm{,}*\frm{.}\endxy}

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 

More information about the Xy-pic mailing list