LaTeX: outline with lines?
Denis Girou
Denis.Girou at idris.fr
Sun May 16 23:26:10 CEST 1999
-----------------------------------------------------------------------------
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.
-----------------------------------------------------------------------------
>>>>> "Peter.Davis" == peterfdavis <peterfdavis at my-dejanews.com> writes:
Peter.Davis> I want to put a hierarchy diagram in my LaTeX document, something like
Peter.Davis> this:
Peter.Davis> Level 1
Peter.Davis> |
Peter.Davis> |-- Level 2
Peter.Davis> | |
Peter.Davis> | |-- Level 3
Peter.Davis> | +-- Level 3
Peter.Davis> +-- Level 2
Peter.Davis> etc. Are there any packages for doing something like this in LaTeX
Peter.Davis> (with dvips) automatically? I've looked at the pstricks tree stuff, but
Peter.Davis> this doesn't seem to match what I'm looking for.
There are many packages to draw structured diagrams and trees. Choosing one
depend on various conditions, and you must explore their documentations to
found the one which would satisfy the best your needs.
Using PSTricks, you can draw your diagram as a structured one using
the general "psmatrix" environment or as a tree. I give you both examples.
\documentclass{article}
\usepackage{pst-tree}
% Level 1
% |
% |-- Level 2
% | |
% | |-- Level 3
% | +-- Level 3
% +-- Level 2
\pagestyle{empty}
\begin{document}
% Drawn as general structured diagram in a matrix of cells
\begin{psmatrix}[colsep=-0.2,rowsep=0.2]
[name=Level1] Level 1 \\
& [name=Level21] Level 21 \\
& & [name=Level31] Level 31 \\
& & [name=Level32] Level 32 \\
& [name=Level22] Level 22 \\
\end{psmatrix}
\psset{angleA=-90,angleB=180,armB=0,nodesep=0.1}
\ncangle{Level1}{Level21}
\ncangle{Level1}{Level22}
\ncangle{Level21}{Level31}
\ncangle{Level21}{Level32}
\vspace{2cm}
% Drawn as a tree (the bounding box is inaccurate)
\newcommand{\MyTree}{%
\pstree[treemode=R,treeflip=true,treesep=-0.7,levelsep=1,nodesep=0.1]%
{\TR{Level 1}}
{\Tn
\pstree{\TR{Level 21}}
{\Tn
\TR{Level 31}
\TR{Level 32}}
\tspace{-1}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}}
\renewcommand{\psedge}{\ncangle[angleA=-90,angleB=180,armB=0]}
\MyTree
\psset{showbbox=true}
\MyTree
\end{document}
Nevertheless, in the first case, you must draw the line connections
explicitely, which is painful if you have a huge diagram or many ones.
In the second case, as you need a special disposition of leaves, you must
use a negative value for the "treesep" parameter. But, as you can see
if you ask to show it ("showbbox=true"), the picture size (the corresponding
"bounding box") is not correctly computed in this case. So, you must adjust
vertically the position of the diagram. One time more, it is not pleasant if
you have several of them.
As I found the idea useful, I try to add a complete and clean solution
to the `pst-tree' package. There are in fact many different cases to test,
according the direction of the tree and the order of management of the leaves.
D.G.
\documentclass{article}
\usepackage{pst-tree}
% Definition of "treealign" and "thistreealign" parameters, which can take
% the values: center (default), left, right, down or up.
% Leaves are aligned starting in this direction.
% D.G. - May 15, 1999
\makeatletter
% D.G. modification begin - May. 15, 1999
\def\pstree at leftalign{\edef\psk at treealign{\z@}}
\def\pstree at downalign{\edef\psk at treealign{\z@}}
\def\pstree at centeralign{\edef\psk at treealign{\@ne}}
\def\pstree at rightalign{\edef\psk at treealign{\tw@}}
\def\pstree at upalign{\edef\psk at treealign{\tw@}}
\def\pstree at thisleftalign{\edef\psk at thistreealign{\z@}}
\def\pstree at thisdownalign{\edef\psk at thistreealign{\z@}}
\def\pstree at thiscenteralign{\edef\psk at thistreealign{\@ne}}
\def\pstree at thisrightalign{\edef\psk at thistreealign{\tw@}}
\def\pstree at thisupalign{\edef\psk at thistreealign{\tw@}}
\def\psset at treealign#1{%
\@ifundefined{pstree@#1align}%
{\@pstrickserr{Bad `treealign' parameter value: `#1'}\@ehpa}%
{\csname pstree@#1align\endcsname}}
\def\psset at thistreealign#1{%
\@ifundefined{pstree@#1align}%
{\@pstrickserr{Bad `treealign' parameter value: `#1'}\@ehpa}%
{\csname pstree at this#1align\endcsname}}
\psset at treealign{center}
% D.G. modification end
\def\pstree at setlevelpar{%
\advance\pstreelevel1
\let\psk at thislevelsep\relax
\let\psk at thistreesep\relax
\let\psk at thistreefit\relax
% D.G. modification begin - May. 15, 1999
\let\psk at thistreealign\relax
% D.G. modification end
\let\psk at thistreenodesize\relax
\csname pstreehook\romannumeral\pstreelevel\endcsname
\use at par
\ifx\psk at thistreesep\relax
\let\psk at thistreesep\psk at treesep
\fi
\ifx\psk at thistreenodesize\relax
\let\psk at thistreenodesize\psk at treenodesize
\fi
\ifx\psk at thistreefit\relax
\let\psk at thistreefit\psk at treefit
\fi
% D.G. modification begin - May. 15, 1999
\ifx\psk at thistreealign\relax
\let\psk at thistreealign\psk at treealign
\fi
% D.G. modification end
\ifx\psk at thislevelsep\relax
\let\psk at thislevelsep\psk at levelsep
\let\psk at thislevelsepmode\psk at levelsepmode
\fi
\ifnum\psk at treemode=\pstree at predmode\else
\global\advance\pstreecnt1
\edef\pstree at thetree{\the\pstreecnt}%
\let\pstree at predmode\psk at treemode
\fi
\ifx\psk at thislevelsepmode\relax
\pst at dimg=\psk at thislevelsep\relax
\pst at cntg=0\@nameuse{%
pstree at levelsepadjust-\pstree at thetree-\the\pstreelevel}%
\advance\pst at dimg\pst at cntg sp
\edef\psk at thislevelsep{\number\pst at dimg sp}%
\fi
\ifnum\psk at treemode>1
\def\pst at tposflip{1 sub neg }%
\else
\def\pst at tposflip{}%
\fi
\ifx\pstree at bboxadjust\@empty\else
\xdef\pstree at treebboxadjust{%
\pstree at bboxadjust
\ifpsshowbbox\noexpand\pstree at showbbox\fi}%
\gdef\pstree at bboxadjust{}%
\fi
\let\pst at thispsbox\@skiplevelfalse}
\def\pstree at vertical#1{%
\pst at cntg=\ifpstreeflip-\fi\wd\pst at hbox
\divide\pst at cntg 2
% D.G. modification begin - May. 15, 1999
%\pstree at add\pstree at theleftprofile
%\pstree at add\pstree at therightprofile
\ifnum\psk at thistreealign=\z@
\ifpstreeflip
\pstree at add\pstree at theleftprofile
\pstree at add\pstree at theleftprofile
\else
\pstree at add\pstree at therightprofile
\pstree at add\pstree at therightprofile
\fi
\else
\ifnum\psk at thistreealign=\@ne
\pstree at add\pstree at theleftprofile
\pstree at add\pstree at therightprofile
\else % \psk at thistreealign=\tw@
\ifpstreeflip
\pstree at add\pstree at therightprofile
\pstree at add\pstree at therightprofile
\else
\pstree at add\pstree at theleftprofile
\pstree at add\pstree at theleftprofile
\fi
\fi
\fi
% D.G. modification end
\pst at dimg=\psk at thislevelsep\relax
\ifx\psk at thislevelsepmode\relax
\pstree at vertlevelsepadjust{#1}%
\fi
\global\setbox\pstree at box=\hbox{%
\vrule height \pst at tempc sp depth \pst at tempd sp width \z@
\unhbox\pstree at rootbox
% D.G. modification begin - May. 15, 1999
%#1\pst at dimg\hbox to\z@{\hss\unhbox\pst at hbox\hss}}%
\ifnum\psk at thistreealign=\z@
#1\pst at dimg\hbox to\z@{\unhbox\pst at hbox\hss}%
\else
\ifnum\psk at thistreealign=\@ne
#1\pst at dimg\hbox to\z@{\hss\unhbox\pst at hbox\hss}%
\else % \psk at thistreealign=\tw@
#1\pst at dimg\hbox to\z@{\hss\unhbox\pst at hbox}%
\fi
\fi}%
% D.G. modification end
\if at skiplevel
\skiplevel at vertical
\else
\endgroup
\fi
\edef\pstree at leftprofile{\pst at tempa,\pstree at theleftprofile}%
\edef\pstree at rightprofile{\pst at tempb,\pstree at therightprofile}%
\pst at dimc=\ht\pstree at box
\pst at dimd=\dp\pstree at box
\ifpsshowbbox
\pstree at max\pstree at leftprofile\pst at cntg
\pst at dima=\pst at cntg sp
\pstree at max\pstree at rightprofile\pst at cntg
\pst at dimb=\pst at cntg sp
\pstree at showbbox
\fi
\dp\pstree at box=\z@
\ht\pstree at box=\z@
\pstree at restorevalues
\pssubtree at vertical
\global\let\pstree at treebboxadjust\pstree at savebboxadjust
\endgroup
\ifnum\pstreelevel>\z@\expandafter\ignorespaces\fi}
\def\pstree at horizontal{%
\ifdim\wd\pst at hbox=\z@\else
\@pstrickserr{Extraneous space in tree successors}\@ehpa
\fi
\pst at cntg=\ifpstreeflip\ht\else\dp\fi\pst at hbox
\divide\pst at cntg 2
% D.G. modification begin - May. 15, 1999
%\pstree at add\pstree at theupprofile
%\pstree at add\pstree at thedownprofile
\ifnum\psk at thistreealign=\z@
\pstree at add\pstree at thedownprofile
\pstree at add\pstree at thedownprofile
\else
\ifnum\psk at thistreealign=\@ne
\pstree at add\pstree at thedownprofile
\pstree at add\pstree at theupprofile
\else % \psk at thistreealign=\tw@
\pstree at add\pstree at theupprofile
\pstree at add\pstree at theupprofile
\fi
\fi
% D.G. modification end
% DG/SR modification begin - Sep. 24, 1997 - Patch 3
%\ifx\psk at thislevelsepmode\relax
%\pstree at horizlevelsepadjust
%\fi
% DG/SR modification end
\pst at dimg\psk at thislevelsep\relax
\global\setbox\pstree at box=\hbox{%
\unhbox\pstree at rootbox
\kern\if at psrighttree\else-\fi\pst at dimg
% D.G. modification begin - May. 15, 1999
%\ifpstreeflip\lower\else\raise\fi\pst at cntg sp\box\pst at hbox}%
\ifnum\psk at thistreealign=\z@
\ifpstreeflip\multiply\pst at cntg\tw@\lower\pst at cntg sp\fi
\else
\ifnum\psk at thistreealign=\@ne
\ifpstreeflip\lower\else\raise\fi\pst at cntg sp
\else % \psk at thistreealign=\tw@
\ifpstreeflip\else\multiply\pst at cntg\tw@\raise\pst at cntg sp\fi
\fi
\fi
\box\pst at hbox}%
% D.G. modification end
% DG/SR modification begin - Sep. 24, 1997 - Patch 3
\ifx\psk at thislevelsepmode\relax
\pstree at horizlevelsepadjust
\fi
% DG/SR modification end
\if at psrighttree
\pst at dimh=\pst at dimg
\pstree at max\pstree at therightprofile\pst at cntg
\global\advance\pst at dimh\pst at cntg sp
\global\pst at dimg=\pst at tempa sp
\else
\pstree at max\pstree at theleftprofile\pst at cntg
\global\advance\pst at dimg\pst at cntg sp
\global\pst at dimh=\pst at tempb sp
\fi
\if at skiplevel
\skiplevel at horizontal
\else
\endgroup
\fi
\pst at dima=\pst at dimg
\pst at dimb=\pst at dimh
\edef\pstree at upprofile{\pst at tempc,\pstree at theupprofile}%
\edef\pstree at downprofile{\pst at tempd,\pstree at thedownprofile}%
\dp\pstree at box=\z@
\ht\pstree at box=\z@
\wd\pstree at box=\z@
\ifpsshowbbox
\pstree at max\pstree at upprofile\pst at cntg
\pst at dimc=\pst at cntg sp
\pstree at max\pstree at downprofile\pst at cntg
\pst at dimd=\pst at cntg sp
\pstree at showbbox
\fi
\pstree at restorevalues
\pssubtree at horizontal
\endgroup
\ifnum\pstreelevel>\z@\expandafter\ignorespaces\fi}
\makeatother
\psset{showbbox=true}
\pagestyle{empty}
\begin{document}
\renewcommand{\psedge}{\ncangle[angleA=-90,angleB=180,armB=0]}
\pstree[treemode=R,treealign=down,treefit=loose,
treesep=0.3,levelsep=1,nodesep=0.1]%
{\TR{Level 1}}
{\Tn
\pstree{\TR{Level 21}}
{\Tn
\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\renewcommand{\psedge}{\ncangle[angleA=-90,angleB=90]}
\pstree{\TR{Level 1}}
{\pstree{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\pstree[treealign=left]%
{\TR{Level 1}}
{\pstree{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\pstree[treealign=right]%
{\TR{Level 1}}
{\pstree{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\clearpage
\vspace*{-2cm}
\pstree[thistreealign=right]%
{\TR{Level 1}}
{\pstree{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\pstree[thistreealign=left]%
{\TR{Level 1}}
{\pstree[thistreealign=right]%
{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\psset{treeflip=true}
\pstree[thistreealign=right]%
{\TR{Level 1}}
{\pstree{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\pstree[thistreealign=left]%
{\TR{Level 1}}
{\pstree[thistreealign=right]%
{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\clearpage
\psset{treemode=R,treeflip=false}
\renewcommand{\psedge}{\ncangle[angleA=0,angleB=180]}
\pstree{\TR{Level 1}}
{\pstree{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\pstree[treealign=down]%
{\TR{Level 1}}
{\pstree{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\pstree[treealign=up]%
{\TR{Level 1}}
{\pstree{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\clearpage
\vspace*{-2cm}
\pstree[thistreealign=up]%
{\TR{Level 1}}
{\pstree{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\pstree[thistreealign=down]%
{\TR{Level 1}}
{\pstree[thistreealign=up]%
{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\psset{treeflip=true}
\pstree[thistreealign=up]%
{\TR{Level 1}}
{\pstree{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\vspace{1cm}
\pstree[thistreealign=down]%
{\TR{Level 1}}
{\pstree[thistreealign=up]%
{\TR{Level 21}}
{\TR{Level 31}
\TR{Level 32}}
\TR{Level 22}
\TR{Level 23}
\TR{Level 24}}
\end{document}
-----------------------------------------------------------------------------
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