2

I'm trying to draw flowcharts and I looked at a few packages. As I'm more familiar with pstricks I chose it, and as I checked the examples I'm trying to draw it with the psmatrix environment.

Our teacher has told us that the "Initializations" should be written in a parallelogram, and when I tried to draw that in my flowchart I had no idea of what syntax should I use for a parallelogram!

Is there any specific command for that?

Should I use \psdiabox with a particular angle in order to get the parallelgram? If yes, how should I define the angle?

Here is an example of what I'm trying to draw where I want to have the red box - "Initialization" - as a parallelogram instead of a rectangle.

enter image description here

‎\documentclass{article}‎
‎\usepackage{pstricks}‎
‎\usepackage{pst-node}‎
‎\usepackage{pst-blur}‎
‎\definecolor{Pink}{rgb}{1.,0.75,0.8}‎
‎\pagestyle{empty}‎
‎\begin{document}‎


‎\vspace{0.5cm}‎
‎\small‎‎‎
  ‎\psset{shadowcolor=black!70,blur=true}‎
  ‎\begin{psmatrix}[rowsep=0.4,colsep=0.5]‎
    ‎\psovalbox{Begin} \\‎
    ‎\psframebox[‎,fillstyle=solid,fillcolor=red‎]{Initialisations} \\‎
    ‎\psdiabox{Special} &‎
       ‎\psframebox[shadow=true]{Call to SP1} & \psframebox[shadow=true]{Call to SP2} \\‎
    ‎\psframebox{Action 1} \\‎
    ~‎\\‎
    ‎\psframebox{Action 2} \\‎
    ‎\psovalbox{End}‎
    % ‎Links‎
    ‎\ncline{->}{1,1}{2,1}‎
    ‎\ncline{->}{2,1}{3,1}‎
    ‎\ncline{->}{3,1}{4,1}<{\textcolor{red}{No}}‎
    ‎\ncline{->}{4,1}{6,1}‎
    ‎\ncline{->}{6,1}{7,1}‎
    ‎\ncline{->}{3,1}{3,2}^{\textcolor{red}{Yes}}‎
    ‎\ncline{->}{3,2}{3,3}‎
    ‎\ncbar[angleA=-90,armB=0,nodesepB=0.25]{->}{3,3}{4,1}‎
  \end{document}
  • pst-node might be useful too. Could you provide a screenshot of something similar to what you're trying to produce? – cmhughes Dec 5 '11 at 5:59
  • @cmhughes I did put an example – Prelude Dec 5 '11 at 6:06
2
\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-node,pst-3d}
\usepackage{pst-blur}
\definecolor{Pink}{rgb}{1.,0.75,0.8}

\makeatletter
\newsavebox\TBox
\newcommand\psParaBox[2][]{{
  \psset{framesep=5pt,gangle=60,#1}%
  \sbox\TBox{\psTilt{\psk@gangle}{\psframebox{\phantom{ #2}}}}%
  \usebox\TBox%  
  \rput(-0.5\wd\TBox,\dimexpr 0.5\ht\TBox-0.5ex\relax){ #2}}}
\makeatother

\pagestyle{empty}
\begin{document}

  \psset{shadowcolor=black!70,blur}
  \begin{psmatrix}[rowsep=0.4,colsep=0.5]
    \psovalbox{Begin} \\
    \psParaBox[fillstyle=solid,fillcolor=red!40]{Initialisations} \\
    \psdiabox{Special} &
       \psframebox[shadow=true]{Call to SP1} & \psframebox[shadow=true]{Call to SP2} \\
    \psframebox{Action 1} \\
    ~\\
    \psframebox{Action 2} \\
    \psovalbox{End}
    % Links
    \ncline{->}{1,1}{2,1}
    \ncline{->}{2,1}{3,1}
    \ncline{->}{3,1}{4,1}<{\textcolor{red}{No}}
    \ncline{->}{4,1}{6,1}
    \ncline{->}{6,1}{7,1}
    \ncline{->}{3,1}{3,2}^{\textcolor{red}{Yes}}
    \ncline{->}{3,2}{3,3}
    \ncbar[angleA=-90,armB=0,nodesepB=0.25]{->}{3,3}{4,1}
  \end{psmatrix}
\end{document}

enter image description here

  • Thank you Herbert for definig the parallelogram in trees . – Prelude Dec 5 '11 at 12:27
  • @ Herbert You designed both of these parallelograms ,would you please tell me what's different between these two in addition to their names – Prelude Dec 5 '11 at 13:50
  • @Negin: the code. the first one defines it on a low level and the second one on a user level, which makes the code more readable. – user2478 Dec 5 '11 at 14:00
  • With the first code I can get a parallelogram but with the second one which you told me has defined the shape on user level I can't get it and my output is still a rectangle ! Should I change anything in this code? – Prelude Dec 5 '11 at 14:38
  • did you viewed the pdf output? – user2478 Dec 5 '11 at 15:22
2

The following defines \psparallelogram[<options>]{<stuff>} that works in the same way \psdiabox and \psframebox works:

enter image description here

\documentclass{article}
\usepackage{pstricks}
\usepackage{pst-node}
\usepackage{pst-blur}
\definecolor{Pink}{rgb}{1.,0.75,0.8}

% ================================
% Source: http://tug.org/pipermail/pstricks/2009/006766.html

\makeatletter
\newdimen\psparallelogramsep
\def\psset@parallelogramsep#1{\pssetlength\psparallelogramsep{#1}}
\psset@parallelogramsep{3mm}
\def\psparallelogrambox{\pst@object{psparallelogrambox}}
\def\psparallelogrambox@i{\pst@makebox\psparallelogrambox@ii}
\def\psparallelogrambox@ii{%
    \begingroup
    \pst@useboxpar
    \pst@dima=\pslinewidth
    \advance\pst@dima by \psframesep
    \pst@dimc=\wd\pst@hbox\advance\pst@dimc by \pst@dima
    \pst@dimb=\dp\pst@hbox\advance\pst@dimb by \pst@dima
    \pst@dimd=\ht\pst@hbox\advance\pst@dimd by \pst@dima
    \setbox\pst@hbox=\hbox{%
        \ifpsboxsep\kern\pst@dima\fi
        \begin@ClosedObj
        \addto@pscode{%
            \psk@cornersize
            \pst@number\pst@dima neg
            \pst@number\pst@dimb neg
            \pst@number\pst@dimc
            \pst@number\pst@dimd .5
            \pst@number\psparallelogramsep
            \tx@Parallelogram}%
            \def\pst@linetype{2}%
            \showpointsfalse
        \end@ClosedObj
        \box\pst@hbox
        \ifpsboxsep\kern\pst@dima\fi%
    }%
    \ifpsboxsep\dp\pst@hbox=\pst@dimb\ht\pst@hbox=\pst@dimd\fi
    \leavevmode\box\pst@hbox
    \endgroup%
}

% From the Frame and Rect PostScript macros
\pst@def{Parallelogram}<{%
/ParallelogramA {
x1 pgs sub y1 moveto
x1 y2 lineto
x2 pgs add y2 lineto
x2 y1 lineto
x1 pgs sub y1 lineto
closepath} def
%
/pgs ED
CLW mul
/a ED
3 -1 roll
2 copy gt { exch } if
a sub
/y2 ED
a add
/y1 ED
2 copy gt { exch } if
a sub
/x2 ED
a add
/x1 ED
1 index 0 eq {pop pop ParallelogramA } { OvalFrame } ifelse}>
\makeatother

\def\pspbox[#1]#2{\makebox[#1]{\psparallelogrambox{#2}}}

% ================================


\pagestyle{empty}
\begin{document}


\vspace{0.5cm}
\small
  \psset{shadowcolor=black!70,blur=true}
  \begin{psmatrix}[rowsep=0.4,colsep=0.5]
    \psovalbox{Begin} \\
    %\psframebox[fillstyle=solid,fillcolor=red]{Initialisations} \\
    \psparallelogrambox[fillstyle=solid,fillcolor=red]{Initialisations} \\
    \psdiabox{Special} &
       \psframebox[shadow=true]{Call to SP1} & \psframebox[shadow=true]{Call to SP2} \\
    \psframebox{Action 1} \\
    ~\\
    \psframebox{Action 2} \\
    \psovalbox{End}
    % Links
    \ncline{->}{1,1}{2,1}
    \ncline{->}{2,1}{3,1}
    \ncline{->}{3,1}{4,1}<{\textcolor{red}{No}}
    \ncline{->}{4,1}{6,1}
    \ncline{->}{6,1}{7,1}
    \ncline{->}{3,1}{3,2}^{\textcolor{red}{Yes}}
    \ncline{->}{3,2}{3,3}
    \ncbar[angleA=-90,armB=0,nodesepB=0.25]{->}{3,3}{4,1}
  \end{psmatrix}
\end{document}

The source for the parallelogram was taken from the PStricks mailing entry on Parallelogram in trees.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.