# [pstricks] Superimposing \psframeboxes, and \psmatrix alignment

Denis Girou Denis.Girou at idris.fr
Mon Sep 2 20:58:28 CEST 2002

>>>>> "Bryn.Humberstone" == Bryn Humberstone <bdh at alphalink.com.au> writes:

Bryn.Humberstone> I'm trying to use pstricks to make a diagram in which I need to create boxes
Bryn.Humberstone> of tables of text like so:

Bryn.Humberstone>     +-----------+
Bryn.Humberstone>     |    ...    |
Bryn.Humberstone>     |    ...    |
Bryn.Humberstone>     |    ...    |
Bryn.Humberstone>     |           |
Bryn.Humberstone>     +-----------+

Bryn.Humberstone> I have no problem using \psframebox and putting arrays inside. The trouble
Bryn.Humberstone> comes because I'd like each box to have a little boxed number in the top
Bryn.Humberstone> left corner like:

Bryn.Humberstone>     +-+---------+
Bryn.Humberstone>     |6|  ...    |
Bryn.Humberstone>     +-+  ...    |
Bryn.Humberstone>     |    ...    |
Bryn.Humberstone>     |           |
Bryn.Humberstone>     +-----------+

Bryn.Humberstone> and there seem to be plenty of ways this could be accomplished but I've been
Bryn.Humberstone> unable to get any of them to work.

Bryn.Humberstone> My idea was to draw the array and then just superimpose another
Bryn.Humberstone> \psframebox{6} at the same location. The main issue is that the my boxes are
Bryn.Humberstone> themselves within a \psmatrix so I don't have access to their exact
Bryn.Humberstone> coordinates. I thought this would not be a problem each of the boxes are
Bryn.Humberstone> within \rnodes, so I have their names. But I'm not sure how I can insist
Bryn.Humberstone> that another psframebox is placed at "the top-left corner of rnode A", say.
Bryn.Humberstone> I tried using \nput but I can't get it to put a new object where I'd like.

I am not absolutely sure of what is the best solution. It seems that we can
use the original macro and just explicitely transfer at the right place the
other small box with the reference. This work in my tests, but perhaps your
usage would be more evoluted and this would not work. Otherwise, a logical way
is to define a special version of the \psframebox macro which add the
definition of a node which will serve to reference the top-left corner later.

I give you the two versions. Make your own tests and see what is better for
you...

Bryn.Humberstone> A more general question that would also (I think) be enough is: is there a
Bryn.Humberstone> pstricks function to convert a node name into a pair of coordinates, so I
Bryn.Humberstone> could do something like:
Bryn.Humberstone> \rput[tl]{\MagicalFunction{A}}{ \psframebox{6} }

Faton Berisha already answered on this point. Just note that these
coordinates will be only known at the PostScript level, not TeX level,
but in such cases it is enough.

Bryn.Humberstone> Another thing that a quick search through the list archives couldn't help me
Bryn.Humberstone> with was psmatrices: I am using them to create a column of these boxes. The
Bryn.Humberstone> problem is that the boxes are different widths and \psmatrix centres
Bryn.Humberstone> the column horizontally by default. Is there a way of changing this so they
Bryn.Humberstone> are left aligned?

Use the "mcol" parameter with the "l" value (see Beta documentation page 28).

D.G.

\documentclass[a4paper]{article}

\usepackage{pstcol}
\usepackage{pst-node}

\newcommand{\MyFrameSep}{0.5}

\newcommand{\MyBox}[2]{%
\psframebox[framesep=\MyFrameSep]{%
\rput[l](-\MyFrameSep,\MyFrameSep){%
\psframebox[fillstyle=solid,fillcolor=black]{\textcolor{white}{#1}}}
\begin{minipage}[t]{3.5cm}
\centering
#2
\end{minipage}}}

\newcommand{\MyDiagram}{%
\begin{psmatrix}
\MyBox{1}{AAAA\\AAAA AAAA\\AAAA} & \MyBox{2}{BBBB\\BBBB\\BBBB\\BBBB} \\
\MyBox{3}{CCCC\\CCCC CCCC CCCC}                                      \\
\MyBox{4}{DDDD}                  & \MyBox{5}{EEEE\\EEEE EEEE\\EEEE}
\end{psmatrix}}

\pagestyle{empty}

\begin{document}

\MyDiagram

\vspace{1cm}
\renewcommand{\MyFrameSep}{0.2}
\MyDiagram

\renewcommand{\MyFrameSep}{0}
\MyDiagram

\vspace{1cm}
\renewcommand{\MyFrameSep}{1}
\MyDiagram

\end{document}

------------------------------------------------------------------------------

\documentclass[a4paper]{article}

\usepackage{pstcol}
\usepackage{pst-node}

\makeatletter

\def\MyPsFrameBox{\pst at object{MyPsFrameBox}}
\def\MyPsFrameBox at i{\pst at makebox\MyPsFrameBox at ii}
\def\MyPsFrameBox 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
% D.G. modification begin - Sep.  2, 2002
\pnode(0,\psframesep){NodeTemp}
% D.G. modification end
\setbox\pst at hbox=\hbox{%
\ifpsboxsep\kern\pst at dima\fi
\begin at ClosedObj
\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
\tx at Frame}%
\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}

\makeatother

\SpecialCoor

\newcommand{\MyFrameSep}{0.5}

\newcommand{\MyBox}[2]{%
\MyPsFrameBox[framesep=\MyFrameSep]{%
\begin{minipage}[t]{3.5cm}
\centering
#2
\end{minipage}}%
\rput[l](NodeTemp){%
\psframebox[fillstyle=solid,fillcolor=black]{\textcolor{white}{#1}}}}

\newcommand{\MyDiagram}{%
\begin{psmatrix}
\MyBox{1}{AAAA\\AAAA AAAA\\AAAA} & \MyBox{2}{BBBB\\BBBB\\BBBB\\BBBB} \\
\MyBox{3}{CCCC\\CCCC CCCC CCCC}                                      \\
\MyBox{4}{DDDD}                  & \MyBox{5}{EEEE\\EEEE EEEE\\EEEE}
\end{psmatrix}}

\pagestyle{empty}

\begin{document}

\MyDiagram

\vspace{1cm}
\renewcommand{\MyFrameSep}{0.2}
\MyDiagram

\renewcommand{\MyFrameSep}{0}
\MyDiagram

\vspace{1cm}
\renewcommand{\MyFrameSep}{1}
\MyDiagram

\end{document}