[pst-tree] Framing parts of a tree
Denis Girou
Denis.Girou at idris.fr
Wed Sep 23 22:45:32 CEST 1998
-----------------------------------------------------------------------------
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.
-----------------------------------------------------------------------------
Recently Paulseph-John Farrugia <farrugia at dolphy.emse.fr> ask in c.t.t.
how to frame a part of a tree in a more powerful way than the one shown in the
documentation for trees pages 50-51, using \ncbox and \ncarcbox.
I don't think that there is a general answer, but we can use several
technics according to the result required.
First, using the boxsize, boxheight, boxdepth, nodesepA, nodesepB parameters
(doc. p. 18), we can control the four dimensions of the box drawn by \ncbox
and \ncarcbox, which allow some customizations. See example 1.
Second, as it is possible to frame a whole tree (see doc. p. 49), we can
frame a part of the whole tree playing with the size (bounding box) of it,
using the xbbl, xbbr, xbbh, xbbd parameters (doc. p. 48). The only
inconvenience is that the size of the tree will not be correctly known by TeX
any more, so it may require to position explicitely the tree or the
surrounding text (another solution is to define an explicit pspicture
environment). See example 2.
Nevertheless, this doesn't answer to all needs. One important wish is to be
able to frame a subtree. Unfortunately, the "natural" way doesn't work
correctly and is unable to compute accurately the size of the box. See what
happen on:
\pstree{\TC}{\TC \psframebox{\pstree{\TC}{\TC \TC \TC}}}
It seems not to be an easy problem... But a solution not too difficult which
seems rather powerful and which accept various customizations is to modify the
way the showbbox parameter work (doc. p. 48). It is because, as explained in
the documentation, with this parameter the exact bounding box of tree
materials can be shown. So hacking the way it produce it effect can offer many
more possibilities (but we must take care to force showbbox to false for all
material inside the frames, otherwise there would be bad side effects).
See example 3.
\documentclass[a4paper,12pt]{article}
\usepackage{pstcol}
\usepackage{pst-tree}
\usepackage{rotating} % CTAN/macros/latex/contrib/supported/rotating
\definecolor{LemonChiffon}{rgb}{1.,0.98,0.8}
\definecolor{PaleGreen} {rgb}{0.88,1,0.88}
\definecolor{Pink} {rgb}{1.,0.75,0.8}
\definecolor{Thistle} {rgb}{0.85,0.75,0.85}
\begin{document}
\begin{center}
\psset{radius=0.5}
\pstree[treesep=1.5,levelsep=4]{\TC}
{\pstree{\TC}
{\TC[name=A]
\pstree{\TC}
{\TC
\TC
\pstree{\TC}
{\TC \TC \TC \TC}}
\TC
\pstree{\TC[name=B]}
{\TC}}}
\ncbox[linestyle=dotted,linearc=1,nodesep=0.5,boxheight=9.2,boxdepth=5.5]{A}{B}
\end{center}
\begin{center}
\psset{radius=0.5}
\psframebox[linestyle=dotted,framearc=0.2,framesep=0.5]{%
\pstree[treesep=1.5,levelsep=4,xbbd=-3,xbbr=-1.2]{\TC}
{\pstree{\TC}
{\TC
\pstree{\TC}
{\TC
\TC
\pstree{\TC}
{\TC \TC \TC \TC}}
\TC
\pstree{\TC}
{\TC}}}}
\end{center}
\vspace{3cm} % To take the xbbd parameter of the previous \pstree into account
Text.
\makeatletter
% Modification of the way the showbbox parameter work, to allow it to do
% various kinds of framing
\newcommand{\SubTreeBox}[1][linestyle=solid]{%
\psset{showbbox=true}
\def\pstree at showbbox{%
\setbox\pstree at box=\hbox{%
\psset{#1} % Local parameters are activated now, to allow framesep change
\advance\pst at dima\psframesep
\advance\pst at dimd\psframesep
\advance\pst at dimb\psframesep
\advance\pst at dimc\psframesep
\psframe(-\pst at dima,-\pst at dimd)(\pst at dimb,\pst at dimc)%
\box\pstree at box}}}
\makeatother
% Can't work correctly in this way!
% \pstree{\TC}{\TC \psframebox{\pstree{\TC}{\TC \TC \TC}}}
\begin{sidewaysfigure}
\begin{center}
\caption{My tree}
\label{fig:Tree}
%
\renewcommand{\psedge}[2]{\ncangle[angleA=90,angleB=-90]{#2}{#1}}
\newcommand{\Node}[2]{%
\Tr[showbbox=false]{\psshadowbox[fillstyle=solid,#1]{#2}}}
%
\psset{levelsep=4,armB=1.5}
%
\vspace{5mm}
\psframebox[framesep=0.8,framearc=0.2]{%
\pstree{\Node{fillcolor=white}{\LARGE Tree}}
{{\SubTreeBox[framesep=0.3,framearc=0.4]
\pstree[showbbox=false]{\Node{fillcolor=Thistle}{AAAAAAA}}
{\Node{fillcolor=Thistle}{AAAA}
\Node{fillcolor=Thistle}{AA}}}
{\SubTreeBox[framesep=0.3,fillstyle=solid,fillcolor=yellow]
\pstree[showbbox=false]{\Node{fillcolor=LemonChiffon}{BBB}}
{\Node{fillcolor=LemonChiffon}{BBBB}
\Node{fillcolor=LemonChiffon}{BBBBBBB}
\pstree{\Node{fillcolor=LemonChiffon}{BBB}}
{\Node{fillcolor=LemonChiffon}{BBBB}
\Node{fillcolor=LemonChiffon}{B}
\Node{fillcolor=LemonChiffon}{BBB}}
\Node{fillcolor=LemonChiffon}{BBB}}}
{\SubTreeBox[framesep=0.3,framearc=0.2,linecolor=red,
doubleline=true]
\pstree[showbbox=false]{\Node{fillcolor=Pink}{CCCC}}
{\Node{fillcolor=Pink}{CC}
\Node{fillcolor=Pink}{CCCCCC}
\Node{fillcolor=Pink}{CCCCC}
\Node{fillcolor=Pink}{CCC}}}}}
\end{center}
\end{sidewaysfigure}
\end{document}
D.G.
-----------------------------------------------------------------------------
The list interface (subscription, information, access to the archives) is on:
http://www.tug.org/cgi-bin/lwgate/pstricks
Otherway to unsubscribe, send mail to pstricks-request at mail.tug.org
with a blank subject and in body the line unsubscribe <email-address>
-----------------------------------------------------------------------------
More information about the PSTricks
mailing list