为什么 \psbrace 的对角线选项 nodesepB(A) 失败?

为什么 \psbrace 的对角线选项 nodesepB(A) 失败?
\documentclass[border=10pt,pstricks,12pt]{standalone}
\usepackage{pstricks-add}

\begin{document}
\begin{pspicture}[showgrid](4,4)
\pnode(0,0){A}
\pnode(4,4){B}
\psbrace[singleline,linestyle=dashed,ref=lC,linewidth=1pt,nodesepB=0.5cm](A)(B){Text I}
\psbrace[singleline,linestyle=dotted,ref=lC,linewidth=1pt,nodesepB=0.5cm](3,4)(0,1){Text II}
\end{pspicture}
\end{document}

在此处输入图片描述

问题:

仅适用于singleline。这是 PSTricks 的功能,也可以将其作为 Asymptote 代码放在下面!

这是\psbrace带有选项的 Asymptote 代码singleline。它基于

/radius1 \psk@braceWidthOuter def
/radius2 \psk@braceWidthInner def
/Length \pst@tempA \pst@tempB Pyth2 def
/Left { Length \psk@bracePos\space mul } bind def
/Right { Length Left sub } bind def

在此处输入图片描述

import graph;
import math;

size(15cm,0);
defaultpen(linewidth(1.5bp));
real xmin=0,xmax=4;
real ymin=0,ymax=4;
real dxmin=0.35;
real dxmax=dxmin;
real dymin=dxmin;
real dymax=dxmax;

xaxis(Label("$x$",position=Relative(1),align=2NE),
xmin-dxmin,xmax+dxmax,RightTicks(Step=1,step=0.5),Arrow(HookHead,1mm),above=true);
yaxis(Label("$y$",position=Relative(1),align=N+E),
ymin-dymin,ymax+dymax,LeftTicks (Step=1,step=0.5,OmitTick(0)),Arrow(HookHead,1mm),above=true);


add(grid(4,4,blue+dashed+0.5pt));
//--
void pstLabelAB(pair A, pair B, Label L="", pen Labelcolor=currentpen,
real dis=1, real d=6, real posLabel=0.5, bool line=true,
pen fillframe=invisible, pen drawframe=invisible, real xmargin=5pt,real ymargin=5pt,
bool rot=true, filltype Fillbackground=Fill(white),
arrowbar arrow=None, arrowbar bar=None, pen sty=currentpen)
{
pair M,N;
M=A+dis/10*dir(degrees(B-A)+90);
N=B+dis/10*dir(degrees(B-A)+90);
path  h = N--M;
real rotate_angle = degrees(dir(h));
//====
frame f;
box(f,Label(L,invisible),xmargin=xmargin,ymargin=ymargin,p=invisible,filltype=Fillbackground);
label(f,L,Labelcolor,FillDraw(fillframe,drawframe));
(rot==false) ? add(f,position=relpoint(h,posLabel)) : add(rotate(rotate_angle)*f,position=relpoint(h,posLabel)+d/10*dir(rotate_angle-90));
}
//---
void psbrace(picture pic=currentpicture, pair A, pair B, 
             real braceWidthInner=linewidth()/5, real braceWidthOuter=linewidth()/5, real bracePos=0.5,
             Label L="", pen textcolor=currentpen, real nodesepB=0, real nodesepA=0.5, real rot=0,
             filltype Labelbackground=Fill(invisible),
             pen p=currentpen)
{
real Length=abs(B-A), Left=bracePos*Length, Right=Length-Left;
pair A1=A+braceWidthInner*unit(B-A);
transform tr=rotate(90,A1);
pair A2=(tr*A), A3=A2+(Left-braceWidthInner-braceWidthOuter)*unit(B-A);
pair A4=A3+braceWidthOuter*unit(A2-A1);
path pathAfirst=arc(A1,braceWidthInner,degrees(A-A1),degrees(A-A1)+90),
pathAsecond=arc(A4,braceWidthOuter,degrees(A3-A4),degrees(A3-A4)-90);
draw(pathAfirst..relpoint(pathAfirst,1)--relpoint(pathAsecond,0)..pathAsecond,p);
//
pair B1=B+braceWidthInner*unit(A-B);
transform tr1=rotate(-90,B1);
pair B2=(tr1*B),B3=B2+(Right-braceWidthInner-braceWidthOuter)*unit(A-B);
pair B4=B3+braceWidthOuter*unit(A2-A1);
path pathBfirst=arc(B1,braceWidthInner,degrees(B-B1),degrees(B-B1)-90),
pathBsecond=arc(B4,braceWidthOuter,degrees(B3-B4),degrees(B3-B4)+90);
draw(pathBfirst..relpoint(pathBfirst,1)--relpoint(pathBsecond,0)..pathBsecond,p);
//-----------------------------------------
pstLabelAB(A,B,rotate(rot)*L,dis=nodesepB,posLabel=nodesepA,d=0,
           xmargin=2,ymargin=2,Labelcolor=textcolor,line=false,Fillbackground=Labelbackground);
}
psbrace((0,0),(4,4),"Text I",rot=0,nodesepB=-10,textcolor=red,dashed+red);
psbrace((0,0),(4,4),"Text I",rot=90,nodesepB=-10,nodesepA=.45,textcolor=red,invisible);
psbrace((3,4),(0,1),"Text II",rot=0,nodesepB=-10,textcolor=red,dotted+blue);
psbrace((3,4),(0,1),"Text II",rot=90,nodesepB=-10,nodesepA=.4,textcolor=red,invisible);
psbrace((0,2),(4,2),"pstricks",rot=90,nodesepB=-10,textcolor=red);
psbrace((0,2),(4,2),"pstricks",rot=90,textcolor=green,invisible);
psbrace((3,0),(3,4),"$\int\limits_1^{\infty}\frac{1}{x^2}\,dx=1$",nodesepB=-8,textcolor=green,dotted);
shipout(bbox(3mm,invisible));

在此处输入图片描述

答案1

对于非垂直或水平的支架,您必须同时使用:(nodesepA水平移位)和nodesepB(垂直移位)。对于 45 度,您可以使用nodesep

\documentclass[border=10pt,pstricks,12pt]{standalone}
\usepackage{pstricks-add}

\begin{document}
\begin{pspicture}[showgrid](4,4)
\pnode(0,0){A}
\pnode(4,4){B}
\psbrace[singleline,linestyle=dashed,ref=lC,linewidth=1pt,nodesep=5mm](A)(B){Text I}
\psbrace[singleline,linestyle=dotted,ref=lC,linewidth=1pt,nodesep=-5mm](3,4)(0,1){Text II}
\end{pspicture}
\end{document}

两者都显示在文档的示例中。

在此处输入图片描述

相关内容