4

My paper contains the following PSTricks picture. It displays a square on the left, and two squares on the right - top and bottom. It describes a process where the square on the left can be in either one of two states - either the top-right or the bottom-right state:

\begin{pspicture}(45,90)
\psframe[fillstyle=solid,fillcolor=green!20](0,20)(30,50)
\rput(15,35){V=3}
\psline{->}(35,25)(45,15)
\psline{->}(35,45)(45,55)
\end{pspicture}
\begin{pspicture}(45,90)
\psframe[fillstyle=solid,fillcolor=green!20](0,40)(30,70)
\psline[linecolor=black,linestyle=dotted](15,40)(15,70)
\rput{90}(7,55){V>2}
\rput{90}(22,55){V<1}
\psline{->}(35,55)(45,55)
\psframe[fillstyle=solid,fillcolor=green!20](0,0)(30,30)
\psline[linecolor=black,linestyle=dashed](15,0)(15,30)
\rput{90}(7,15){1$\leq$V$\leq$2}
\rput{90}(22,15){1$\leq$V$\leq$2}
\end{pspicture}

It is important that the three squares are identical (they represent the same square), so, I want them to also look identical in the PSTricks code. However, in order to arrange them vertically, I had to change their coordinates, so the left square is "(0,20)(30,50)", the top-right is "(0,40)(30,70)", and the bottom right is "(0,0)(30,30)".

Is there a way to insert a vertical shift, such that, I can just copy an existing psframe, add a shift, and it will be shifted correctly?

(I hope I made myself clear)

2 Answers2

3

Yes. Insert the \psframe inside an \rput{0}(<xshift>,<yshift>){<stuff>} and define the frame in a command, for consistency:

enter image description here

\newcommand{\myframe}[1][]{%
  \psframe[fillstyle=solid,fillcolor=green!20,#1](0,20)(30,50)}

%...

\begin{pspicture}(45,90)
  \myframe
  %...
  \rput{0}(0,20){\myframe}% Translate \myframe vertically up 20 y-units
  \rput{0}(0,-20){\myframe}% Translate \myframe vertically down 20 y-units
  %...
\end{pspicture}
%...

The optional argument of \myframe[<opt arg>] allows you to pass optional stuff, like fillcolor=green!50!red to change things as needed for other frames. With this in mind, consider drawing the entire picture in a single pspicture environment.

Werner
  • 603,163
  • 1
    why do you always use {0} for \rput?? –  Oct 06 '13 at 05:21
  • @Herbert: It is convention for {.} to denote mandatory arguments. As such, it's a habit that I have adopted, but could change. There is also no clear mention of which is mandatory/optional under section 24 Placing and rotating whatever of the main PStricks documentation (p 41). For \put*arg{<rot>}(<coor>){<stuff>}, yes, there is mention that {<rot>} is optional, but mandatory when you leave out the optional (<coor>)? So \rput(.){.}, \rput{.}(.){.} and \rput{.}{.} are valid, but not \rput{.}... – Werner Oct 08 '13 at 19:37
  • on TeX-Level everything can be an optional argument! PSTricks itself uses <.>, (.), {.}, [.]. Only on LaTeX level we have {.} as a mandatory argument. Compare beamer, it also has {.} as an optional argument. –  Oct 08 '13 at 19:45
0

define the squares as nodes then you can use symbolic coodinates for the connections:

\documentclass[border=20pt]{standalone}
\usepackage{pstricks-add}
\psset{unit=1mm}
\makeatletter
\def\myframe{\@ifnextchar[\myframe@i{\myframe@i[]}}
\def\myframe@i[#1](#2)#3#4{%
  \rput(#2){\rnode{#4}{%
    \psTextFrame[fillstyle=solid,fillcolor=green!20,#1](-15,-15)(15,15){#3}}}}
\makeatother

\begin{document}

\begin{pspicture}(-20,-50)(80,50)
\myframe(0,0){V=3}{left}
\myframe[rot=90](50,-30){\parbox{30mm}{\centering
  $1\leq V\leq2$\\  \psline[linestyle=dashed](-15,0)(15,0)\\[5pt]
  $1\leq V\leq2$}}{down}
\myframe[rot=90](50,30){\parbox{30mm}{\centering
  $V>2$\\   \psline[linestyle=dotted](-15,0)(15,0)\\[5pt]
  $V>1$}}{up}
%
\ncline[nodesep=16,doubleline]{->}{left}{down}\naput{foo}
\ncline[nodesep=16,doubleline]{->}{left}{up}\nbput{bar}
\ncline[nodesepA=16,nodesepB=-30]{->}{up}{up}\ncput*{baz}
\end{pspicture}

\end{document}

enter image description here

The syntax of \myframe is:

\myframe[optarg](x,y){text}{node name}