[pstricks] A node connection with centered arrow?

Denis Girou Denis.Girou at idris.fr
Mon Apr 22 21:26:07 CEST 2002


>>>>> "Blair.Hall" == Blair Hall <b.hall at irl.cri.nz> writes:

    Blair.Hall> I have found the archive (2000) and copied the TeX code I found there.
    Blair.Hall> This works fine for \ncline, as far as I can tell.
    Blair.Hall> However, I have a problem with \ncbar.

    Blair.Hall> The following code does not work properly:

    Blair.Hall>      \documentclass{article}
    Blair.Hall>      \usepackage{pstricks,pst-node}
    Blair.Hall>      \input{pst-ArrowsInside}

    Blair.Hall>      \begin{document}

    Blair.Hall>      \begin{psmatrix}
    Blair.Hall>        \dotnode{1} & \dotnode{2} \\
    Blair.Hall>        \dotnode{4} & \dotnode{3}
    Blair.Hall>      \end{psmatrix}
    Blair.Hall>        \ncline[ArrowInside=->]{1}{2}
    Blair.Hall>        \ncbar[angle=-90,ArrowInside=->]{4}{3}

    Blair.Hall>      \end{document}

    Blair.Hall> I get a centered arrow between nodes 1 and 2, but the bar between 3 and 4 
    Blair.Hall> has no arrow!
    Blair.Hall> (The "pst-ArrowInside" file is simply my copy of the archived code - 
    Blair.Hall> without any changes.)

    Blair.Hall> Any ideas anyone?


  As explained at the beginning of the message you found in the archives of
this list, I gave at this date a solution for the \ncline and \nccurve macros
_only_ (this was the question asked), so obviously it cannot have any effect
for \ncbar as in your case:

http://www.tug.org/pipermail/pstricks/2000/000488.html

> Subject: Re: arrowhead ,,in the middle'' of the line (arc) in psmatrix
> Date: Sun, 3 Dec 2000 23:38:50 +0100 (MET) 

>  In December 97 (see the mailing list archives), I gave a general solution
> for some cases (\psline, \pspolygon, \psbezier). We can adapt it for the case
> of \ncline and \nccurve, redefining the NCLine and NCCurve PostScript macros.


  As said, I gave in December 1997 the modifications of the Line, Polygon and
OpenBezier PostScript macros:

http://www.tug.org/pipermail/pstricks/1997/000093.html


  The general question of arrows inside points or nodes connections cannot
have a generic solution, and each relevant internal PostScript macro must be
modified. Sometimes this is easy to do, as for the Line and NCLine macros,
and sometimes this is really difficult, as for NCCurve (I must say that it
would require real efforts if today I needed to understand again my old
code...)

  I give you here the code for NCBar. Note that the ArrowInsidePos is relative
to the "line" part of the connection, and does not include the two arms.

D.G.


\documentclass{article}

\usepackage{pst-node}

\pagestyle{empty}

\makeatletter

% DG addition begin - Dec. 18/19, 1997

% Adapted from \psset at arrows
\def\psset at ArrowInside#1{%
\begingroup
\pst at activearrows
\xdef\pst at tempg{<#1}%
\endgroup
\expandafter\psset@@ArrowInside\pst at tempg\@empty-\@empty\@nil
\if at pst\else
\@pstrickserr{Bad intermediate arrow specification: #1}\@ehpa
\fi}

% Adapted from \psset@@arrows
\def\psset@@ArrowInside#1-#2\@empty#3\@nil{%
\@psttrue
\def\next##1,#1-##2,##3\@nil{\def\pst at tempg{##2}}%
\expandafter\next\pst at arrowtable,#1-#1,\@nil
\@ifundefined{psas@#2}%
{\@pstfalse\def\psk at ArrowInside{}}%
{\def\psk at ArrowInside{#2}}}

% Default value empty
\def\psk at ArrowInside{}

% Modified version of \pst at addarrowdef
\def\pst at addarrowdef{%
\addto at pscode{%
/ArrowA {
\ifx\psk at arrowA\@empty
\pst at oplineto
\else
\pst at arrowdef{A}
moveto
\fi
} def
/ArrowB {
\ifx\psk at arrowB\@empty \else \pst at arrowdef{B} \fi
} def
% DG addition
/ArrowInside {
\ifx\psk at ArrowInside\@empty \else \pst at arrowdefA{Inside} \fi
} def
}}

% Adapted from \pst at arrowdef
\def\pst at arrowdefA#1{%
\ifnum\pst at repeatarrowsflag>\z@
/Arrow#1c [ 6 2 roll ] cvx def Arrow#1c
\fi
\tx at BeginArrow
\psk at arrowscale
\@nameuse{psas@\@nameuse{psk at Arrow#1}}
\tx at EndArrow}

% ArrowInsidePos parameter (default value 0.5)
\def\psset at ArrowInsidePos#1{\pst at checknum{#1}\psk at ArrowInsidePos}%
\psset at ArrowInsidePos{0.5}

% DG addition end


% DG modification begin - Dec. 3, 2000 and Apr. 22, 2002

% Redefinition of the PostScript NCLine macro to print the intermediate
% arrow on a line connection joining two nodes
\pst at def{NCLine}<{%
NCCoor
tx at Dict begin
  ArrowA
  CP
% D.G. addition begin - Dec.  3, 2000
  4 copy
  /y1 ED
  /x1 ED
  /y2 ED
  /x2 ED
  x1
  y1
  x2 x1 sub \psk at ArrowInsidePos mul x1 add
  y2 y1 sub \psk at ArrowInsidePos mul y1 add
  ArrowInside
  pop pop pop pop
% D.G. addition end
  4 2 roll
  ArrowB
  lineto
  pop pop
end}>

% Redefinition of the PostScript NCBar macro to print the intermediate
% arrow on a bar connection joining two nodes
\pst at def{NCBar}<{%
GetEdgeA
GetEdgeB
GetArmA
GetArmB
/mtrx AngleA matrix rotate def
xA2 yA2 mtrx itransform
pop
xB2 yB2 mtrx itransform
pop
sub dup 0 mtrx transform
3 -1 roll
0 gt { /yB2 exch yB2 add def /xB2 exch xB2 add def }
     { /yA2 exch neg yA2 add def /xA2 exch neg xA2 add def } ifelse
mark
ArmB
0 ne { xB1 yB1 } if
xB2 yB2 xA2 yA2
% D.G. addition begin - Apr. 22, 2002
4 copy
/y1 ED
/x1 ED
/y2 ED
/x2 ED
x1
y1
x2 x1 sub \psk at ArrowInsidePos mul x1 add
y2 y1 sub \psk at ArrowInsidePos mul y1 add
ArrowInside
pop pop pop pop
% D.G. addition end
ArmA
0 ne { xA1 yA1 } if
tx at Dict begin
  false
  Line
end
/LPutVar [ xB1 yB1 xB2 yB2 xA2 yA2 xA1 yA1 ] cvx def
/LPutPos { LPutLines } def
/HPutPos { HPutLines } def
/VPutPos { VPutLines } def }>

% D.G. modification end

\makeatother

\begin{document}

\psset{arrowscale=3,ArrowInside=->}

\Huge

\begin{psmatrix}[rowsep=3,colsep=3]
  A & B \\
  C & D
\end{psmatrix}
\ncline{1,1}{2,1}
\ncline[ArrowInsidePos=0.25]{1,2}{2,2}
\ncline[linecolor=blue,ArrowInside=-|,ArrowInsidePos=0.75]{1,1}{2,2}
\ncbar[arm=1,angle=90,linecolor=red]{1,1}{1,2}
\ncbar[arm=2,angle=-90,linecolor=green,
       ArrowInside=-*,ArrowInsidePos=0]{2,1}{2,2}
\ncbar[arm=3,linecolor=magenta,ArrowInsidePos=1]{1,2}{2,2}

\end{document}



More information about the PSTricks mailing list