[pstricks] psmatrix and baseline alignment

Denis Girou Denis.Girou at idris.fr
Thu Oct 24 21:54:46 CEST 2002


>>>>> "Joachim.Nadler" == Joachim Nadler <jnadler at inferenzsysteme.informatik.tu-darmstadt.de> writes:

    Joachim.Nadler> ...

    Joachim.Nadler> \documentclass{article}

    Joachim.Nadler> \usepackage{pst-node}

    Joachim.Nadler> \setlength{\parskip}{0.5cm}

    Joachim.Nadler> \begin{document}

    Joachim.Nadler> Why is the baseline of a psmatrix aligned with the top of its last line?

    Joachim.Nadler> \par

    Joachim.Nadler> %\begin{minipage}[t]{1.5cm}
    Joachim.Nadler> %\psframebox{
    Joachim.Nadler> %\begin{pspicture}*[0.9](0.5,1.5)
    Joachim.Nadler> \begin{psmatrix}[colsep=1em,rowsep=1ex]
    Joachim.Nadler> a & b \\ c & d \\[4ex] e & f
    Joachim.Nadler> \end{psmatrix}
    Joachim.Nadler> %\end{pspicture}}
    Joachim.Nadler> %\end{minipage}
    Joachim.Nadler> I want this to be aligned with the top of the matrix.

    Joachim.Nadler> \hrulefill

    Joachim.Nadler> \begin{tabular}[t]{@{}cc@{}}
    Joachim.Nadler> a & b \\ c & d \\[4ex] e & f
    Joachim.Nadler> \end{tabular}
    Joachim.Nadler> Like this.

    Joachim.Nadler> How can I do it?
    Joachim.Nadler> If I surrounded the psmatrix with a pspicture, I could use
    Joachim.Nadler> the baseline parameter, but then I would have to specify
    Joachim.Nadler> the size of the pspicture, which I do not know in general.
    Joachim.Nadler> Using a minipage[t] does not seem to help either.

    Joachim.Nadler> \end{document}

  This is clearly an interesting question, but I do not think that it exist
a direct solution at the user level, without low level programmation.
Such wish seems to have not been expected, as the main usage of the "psmatrix"
environment is for non trivial diagrams, which must be formatted as a whole
paragraph.

  I have not try to understood why the "top" parameter of the "minipage"
environment does not give the expected result, when the "bottom" and "center"
parameters give the correct ones. Nevertheless, you can see in my example
with \shortstack that this seems to be a general behavior not related to
PSTricks.

  In any case, it is easy to modify the original code of "psmatrix" to
position vertically the resulting box on the first or last line, as we have
with the "tabular" environment. I add a new "position" parameter for it
(perhaps not a good name, as too general...). You can test this code on your
own cases. But take care also that the type of nodes to choose must be "none".

  I also add examples to position vertically the whole box, just using
a nested "psmatrix" environment.

D.G.


\documentclass{article}

\usepackage{pst-node}

\makeatletter

\def\psset at position#1{\edef\psposition{#1}}
\psset at position{}

\def\psmatrix at ii{%
\KillGlue
\edef\psm at beginmath{%
\ifmmode$\m at th\ifinner\textstyle\else\displaystyle\fi\fi}%
\edef\psm at endmath{\ifmmode$\fi}%
\let\\\psm at cr
\advance\psmatrixcnt 1
\def\psm at thenode{M-\the\psmatrixcnt-\the\psrow-\the\pscol}%
\tabskip\z@
\psrow1
\pscol\z@
\psset at shortput{tablr}%
\leavevmode
% D.G. modification begin - Oct. 20, 2002
%\vbox\bgroup\halign\bgroup&%
\def\pst at temph{t}%
\ifx\psposition\pst at temph
  \vtop
\else
  \def\pst at temph{c}%
  \ifx\psposition\pst at temph
    $\vcenter
  \else
    \vbox
  \fi
\fi
\bgroup\halign\bgroup&%
% D.G. modification end
\begingroup
\global\advance\pscol 1
\csname psrowhook\romannumeral\psrow\endcsname
\csname pscolhook\romannumeral\pscol\endcsname
\psm at beginnode##\psm at endnode\endgroup
\cr}

\def\endpsmatrix{%
\crcr\egroup\unskip\egroup
% D.G. modification begin - Oct. 20, 2002
\def\pst at temph{c}%
\ifx\psposition\pst at temph$\fi
% D.G. modification end
\endgroup}

\makeatother

\newcommand{\PsMatrixA}{%
\psframebox{%
\begin{psmatrix}[colsep=1em,rowsep=1ex]
a & b \\ c & d \\[4ex] e & f
\end{psmatrix}}}

\newcommand{\PsMatrixB}{%
\psframebox{%
\begin{psmatrix}[mnode=none,colsep=1em,rowsep=1ex]
a & b \\ c & d \\[4ex] e & f
\end{psmatrix}}}

\newcommand{\PsMatrixC}{%
\begin{psmatrix}[mnode=r,ref=b,colsep=0]
  \PsMatrixB
\end{psmatrix}}

\newcommand{\PsMatrixD}{%
\begin{psmatrix}[mnode=r,ref=c,colsep=0]
  \PsMatrixB
\end{psmatrix}}

\newcommand{\PsMatrixE}{%
\begin{psmatrix}[mnode=r,ref=t,colsep=0]
  \PsMatrixB
\end{psmatrix}}

\newcommand{\PsMatrixF}{%
\psframebox{%
\begin{psmatrix}[mnode=none,position=b,colsep=1em,rowsep=1ex]
a & b \\ c & d \\[4ex] e & f
\end{psmatrix}}}

\newcommand{\PsMatrixG}{%
\psframebox{%
\begin{psmatrix}[mnode=none,position=c,colsep=1em,rowsep=1ex]
a & b \\ c & d \\[4ex] e & f
\end{psmatrix}}}

\newcommand{\PsMatrixH}{%
\psframebox{%
\begin{psmatrix}[mnode=none,position=t,colsep=1em,rowsep=1ex]
a & b \\ c & d \\[4ex] e & f
\end{psmatrix}}}

\newcommand{\Separator}{\rule{5mm}{0.2mm}X\rule{5mm}{0.2mm}}

\setlength{\parindent}{0cm}

\pagestyle{empty}

\begin{document}

\Separator\PsMatrixA\Separator\PsMatrixB\Separator

\Separator
%
\begin{minipage}{1cm}
  \PsMatrixB
\end{minipage}%
%
\Separator
%
\begin{minipage}[b]{1cm}
  \PsMatrixB
\end{minipage}%
%
\Separator
%
\begin{minipage}[t]{1cm}
  \PsMatrixB
\end{minipage}%
%
\Separator

% The \parbox macro and the "minipage" environment does not position correctly
% a composite box when the "top" aligment is required
\Separator
\parbox[b]{1mm}{\shortstack{a\\b\\c}}
\Separator
\parbox[c]{1mm}{\shortstack{a\\b\\c}}
\Separator
\parbox[t]{1mm}{\shortstack{a\\b\\c}}
\Separator
\parbox[t]{1mm}{a\\b\\c}
\Separator

\Separator\PsMatrixC
\Separator\PsMatrixD
\Separator\PsMatrixE\Separator

\Separator\PsMatrixF
\Separator\PsMatrixG
\Separator\PsMatrixH\Separator

\end{document}



More information about the PSTricks mailing list