[pstricks] Vertical alignment of an inline pspicture?
Jean-Côme Charpentier
jean-come.charpentier at wanadoo.fr
Sun Jun 14 10:51:38 CEST 2009
Troy Woo a écrit :
> Just as tabular and array can be vertically aligned by
> \begin[pos]{tabular} and \begin[pos]{array}{...}, is there a way to
> vertically align a pspicture (inlined)?
>
> Such as \begin[pos]{pspicture}? (which I tried and failed.)
It seems to me that an old version of pspicture have this feature.
Actually, it was \begin{pspicture}[-0.5](...) which shifts the picture
by half of its height. I'm not sure and Herbert will correct me if I
write some garbage :-)
Nowadays, pspicture environment accept optional argument and the key
'shift'. Yhis key indicates the vertical shift of the whole picture.
Example below will be clearer than a long talking:
\documentclass{article}
\usepackage{pstricks}
\makeatletter
\def\cpspicture(#1,#2){%
\@ifnextchar({\pst at cpicture(#1,#2)}%
{\pst at cpicture(0,0)(#1,#2)}%
}
\def\pst at cpicture(#1,#2)(#3,#4){%
\pssetylength\pst at dima{#2}%
\pssetylength\pst at dimb{#4}%
\advance\pst at dimb -\pst at dima
\pst at dimb -.5\pst at dimb
\edef\pictureshift{shift=\the\pst at dimb}%
\expandafter\pspicture\expandafter[\pictureshift](#1,#2)(#3,#4)
}
\let\endcpspicture\endpspicture
\makeatother
\begin{document}
% Without shift parameter
Hello
\begin{pspicture}(-1,-1)(3,3)
\psframe(-1,-1)(3,3)
\end{pspicture}
world!
% In order to center, shift = -(ymax-ymin)/2
% Here: -(3-(-1))/2 = -2
Hello
\begin{pspicture}[shift=-2](-1,-1)(3,3)
\psframe(-1,-1)(3,3)
\end{pspicture}
world!
% Automatic way
Hello
\begin{cpspicture}(-1,-1)(3,3)
\psframe(-1,-1)(3,3)
\end{cpspicture}
world!
\end{document}
Jean-Côme Charpentier
More information about the PSTricks
mailing list