# [Programming] Horizontal trees with various exit

Denis Girou Denis.Girou at idris.fr
Wed May 21 23:09:20 CEST 1997

-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

Working again on complex trees for <Francoise.Coustillas at dept.edfgdf.fr>
who has many complex genealogy trees to draw, with various configurations and
cases, I see that for one kind of them it can be greatly improve.

It's the case of horizontal trees, where we want to be able to fix the
"exit" point for various connections to sub-nodes. By default, we can't.
To do that, as in the first following solution, we must manage by hand all the
connections. It's very heavy on huge and complex trees.

But there is an easy and automatic solution, which consist to redefine the
position of the node before to connect it to subnodes. We must in this case
transfer the current node store in \pssucc macro to a new position.
I write the \SameNode macro to define alias of an existing node, and with that
we can define an \ExitNode macro which redefine position of the node before
the link. See my second solution.

I give you this example as I think it's pedagogical and can be useful.

I update the genealogy examples for that and for other improvements and
simplifications (see http://www.tug.org/applications/PSTricks/Trees).

D.G.

\documentclass{article}

\usepackage{pstricks}
\usepackage{pst-tree}

% Defaut edge
\renewcommand{\psedge}{\ncangle[angleB=180,armB=0.6\baselineskip]}

% Macro to define my node
\newcommand{\MyNode}[1]{%
\TR{\tabcolsep=0mm\begin{tabular}[t]{l}#1\end{tabular}}}

% Definition of nodes
\newcommand{\NodeA}{\MyNode{AAAA\\AA\\AAAA\\AA}}
\newcommand{\NodeB}{\MyNode{BBBB\\BBBB\\BBBB}}
\newcommand{\NodeC}{\MyNode{C\\C\\C\\}}
\newcommand{\NodeD}{\MyNode{DDDD\\DD\\DD\\DDDDDD\\DD}}
\newcommand{\NodeE}{\MyNode{EE\\EEEE}}

\newcommand{\MyTree}{%
\pstree[treemode=R,levelsep=*1cm,href=-1]
{\NodeA}
{\pstree{\NodeB}
{\NodeC}
\pstree{\NodeD}
{\NodeE}}}

\pagestyle{empty}

\begin{document}

\Large

% Default
% -------
\MyTree

% First solution
% --------------

% Macro to define my node
\renewcommand{\MyNode}[2][]{%
\TR[#1]{\tabcolsep=0mm\begin{tabular}[t]{l}#2\end{tabular}}}

% Definition of nodes
\renewcommand{\NodeA}{\MyNode{AAAA\\\rnode{NodeAA}{AA}\\AAAA\\AA}}
\renewcommand{\NodeB}{\MyNode[name=NodeB]{BBBB\\BBBB\\\rnode{NodeBB}{BBBB}}}
\renewcommand{\NodeC}{\MyNode[name=NodeC]{C\\C\\C\\}}
\renewcommand{\NodeD}{\MyNode[name=NodeD]{%
DDDD\\DD\\\rnode{NodeDD}{DD}\\DDDDDD\\DD}}
\renewcommand{\NodeE}{\MyNode[name=NodeE]{EE\\EEEE}}

\vspace{1cm}
{%
\psset{edge=none}
\MyTree
\psset{angleB=180}
\ncangle{NodeAA}{NodeB}
\ncangle{NodeAA}{NodeD}
\ncangle{NodeBB}{NodeC}
\ncangle{NodeDD}{NodeE}
}

% Second solution
% ---------------

% Macro to define my node
\renewcommand{\MyNode}[1]{%
\TR{\tabcolsep=0mm\begin{tabular}[t]{l}#1\end{tabular}}%
\UpdateNode% Execute it if defined to change the position of the node
\gdef\UpdateNode{}} % Remove the new definition of node if it was defined

% Default to update later node position: empty
\def\UpdateNode{}%

% Definition of an exit node different from the entrance one
\newcommand{\ExitNode}[1]{%
\rnode{NodeTemp}{#1}
\gdef\UpdateNode{\SameNode{\pssucc}{NodeTemp}}}

% Denis Girou <Denis.Girou at idris.fr> - May 15, 1997
% To give an alias name to a previous defined one
% \SameNode{B}{A} define a node B equivalent to the predefined node A
% Useful for special connections in trees
\makeatletter
\def\SameNode#1#2{%
\pst at getnode{#1}\pst at tempa
\pst at getnode@{#2}\pst at tempb
\pst at Verb{\pst at nodedict \pst at tempa \pst at tempb def end}}
% From \pst at getnode, but to return the name of node without the first /
\def\pst at getnode@#1#2{%
\pst at expandafter\pst@@getnode@{#1},,\@nil#2}
\def\pst@@getnode@#1,#2,#3\@nil#4{%
\ifx\@empty#3\@empty
\edef#4{N@\pst at zapspace#1 \@empty\space}%
\else
\pst at cntg=#1\relax
\pst at cnth=#2\relax
\edef#4{N at M-\ifnum\psmatrixcnt=\z@ 1\else\the\psmatrixcnt\fi
-\the\pst at cntg-\the\pst at cnth\space}%
\fi}
\makeatother

% Definition of nodes
\renewcommand{\NodeA}{\MyNode{AAAA\\\ExitNode{AA}\\AAAA\\AA}}
\renewcommand{\NodeB}{\MyNode{BBBB\\BBBB\\\ExitNode{BBBB}}}
\renewcommand{\NodeC}{\MyNode{C\\C\\C\\}}
\renewcommand{\NodeD}{\MyNode{DDDD\\DD\\\ExitNode{DD}\\DDDDDD\\DD}}
\renewcommand{\NodeE}{\MyNode{EE\\EEEE}}

\vspace{1cm}
\MyTree

\end{document}

-----------------------------------------------------------------------------
To [un]subscribe to this list, send mail to pstricks-request at mail.tug.org
Leave the subject line blank and in the body put the line