[pstricks] Hexagon Nodes in ptree

Denis Girou Denis.Girou at idris.fr
Mon Jan 6 23:35:34 CET 2003


The following message is a courtesy copy of an article
that has been posted to comp.text.tex as well.

>>>>> "Tan.Woon.Kiong" == Tan Woon Kiong <thomas_sg2000 at yahoo.com> writes:

    Tan.Woon.Kiong> How do I draw trees with labeled nodes that are hexagons? 
    Tan.Woon.Kiong> The macro \pstree gives only up to 4-sides: "\Tdia".

  A possible way is:

\documentclass[a4paper]{article}

\usepackage{pst-tree}

\makeatletter

% Box of an hexagon form built using the code of \psframebox

% The length used for the hexagon (2mm by default)
\newdimen\pshexagonsep
\def\psset at hexagonsep#1{\pssetlength\pshexagonsep{#1}}
\psset at hexagonsep{2mm}

\def\pshexagonbox{\pst at object{pshexagonbox}}

\def\pshexagonbox at i{\pst at makebox\pshexagonbox at ii}

\def\pshexagonbox at ii{%
\begingroup
\pst at useboxpar
\pst at dima=\pslinewidth
\advance\pst at dima by \psframesep
\pst at dimc=\wd\pst at hbox\advance\pst at dimc by \pst at dima
\pst at dimb=\dp\pst at hbox\advance\pst at dimb by \pst at dima
\pst at dimd=\ht\pst at hbox\advance\pst at dimd by \pst at dima
\setbox\pst at hbox=\hbox{%
\ifpsboxsep\kern\pst at dima\fi
\begin at ClosedObj
\addto at pscode{%
\psk at cornersize
\pst at number\pst at dima neg
\pst at number\pst at dimb neg
\pst at number\pst at dimc
\pst at number\pst at dimd
.5
\pst at number\pshexagonsep
\tx at HexagonA}%
\def\pst at linetype{2}%
\showpointsfalse
\end at ClosedObj
\box\pst at hbox
\ifpsboxsep\kern\pst at dima\fi}%
\ifpsboxsep\dp\pst at hbox=\pst at dimb\ht\pst at hbox=\pst at dimd\fi
\leavevmode
\box\pst at hbox
\endgroup}

% From the Frame PostScript macro

\pst at def{HexagonA}<{%
/hgs ED
CLW mul
/a ED
3 -1 roll
2 copy gt { exch } if
a sub
/y2 ED
a add
/y1 ED
2 copy gt { exch } if
a sub
/x2 ED
a add
/x1 ED
1 index 0 eq {pop pop \tx at Hexagon } { OvalFrame } ifelse}>

\pst at def{Hexagon}<{%
x1 hgs add y1              moveto
x1         y1 y2 add 2 div lineto
x1 hgs add y2              lineto
x2 hgs sub y2              lineto
x2         y1 y2 add 2 div lineto
x2 hgs sub y1              lineto
closepath}>

\makeatother

\pagestyle{empty}

\begin{document}

\LARGE

\pshexagonbox{T}
\hfill
\pshexagonbox[hexagonsep=0]{T}
\hfill
\pshexagonbox[hexagonsep=0.1]{T}
\hfill
\pshexagonbox[hexagonsep=0.6]{T}
\hfill
\pshexagonbox[hexagonsep=0.6,framesep=0.6]{T}
\hfill
\pshexagonbox[hexagonsep=-0.2]{T}

\vspace{1cm}

\pshexagonbox{Text}
\hfill
\pshexagonbox[hexagonsep=0.3,framesep=0.3]{Text}
\hfill
\pshexagonbox[hexagonsep=0.4,framesep=0.6]{Text}
\hfill
\pshexagonbox[hexagonsep=0.4,framesep=1]{Text}
\hfill
\pshexagonbox[linecolor=red,fillstyle=solid,fillcolor=cyan,
              doubleline=true,framesep=0.2]{Text}

\vspace{1cm}

\psset{framesep=0.3}

\pshexagonbox{Long text}
\hfill
\pshexagonbox[hexagonsep=0.5]{Long text}
\hfill
\pshexagonbox{\shortstack{Text\\Text\\Text}}
\hfill
\pshexagonbox[hexagonsep=0.4,framesep=0.4]{\shortstack{Text\\Text\\Text}}

\vspace{1cm}

% Trees

\def\Tframe#1{\TR{\psframebox{#1}}}

\def\Thexagon#1{\TR{\pshexagonbox{#1}}}

\psset{framesep=0.2}

\pstree{\Tframe{AAAA}}
       {\pstree{\Tframe{BBBB}}
               {\Tframe{CCCC}}
        \pstree{\Tframe{DDDD}}
               {\Tframe{EEEE}}}
\hfill
\pstree{\Thexagon{AAAA}}
       {\pstree{\Tframe{BBBB}}
               {\Thexagon{CCCC}}
        \pstree{\Thexagon{DDDD}}
               {\Tframe{EEEE}}}


\end{document}


Denis Girou
-- 
--------------------------------------------------------------------------
Institut du Développement et des Ressources en Informatique Scientifique |
Centre National de la Recherche Scientifique                             |
Bâtiment 506 - B.P. 167 - 91403 Orsay Cedex - France                     |
--------------------------------------------------------------------------



More information about the PSTricks mailing list