我想在图表中绘制沿轴分割的两种颜色的箭头。(这应表示以颜色编码区分的混合情况。)这是草图:
下面是一个可供玩的 MWE:
\documentclass{article}
\usepackage{asymptote}
\begin{document}
\begin{asy}
size(10cm);
path p = (0,0)::(1,1){up}::(0,2){down};
draw (p, arrow=Arrow(size=25));
draw (shift((1,0))*p, arrow=Arrow(HookHead, size=25));
\end{asy}
\end{document}
如果箭头形式与默认箭头匹配就太好了,这样它们就可以在图表中一起使用。
我主要对渐近线解决方案感兴趣,但如果 TikZers 和 PSTricksers 有一些东西可以展示,我相信会受到赞赏。
答案1
首先给出一个非常基本的建议:
\begin{filecontents*}{twocoloredline.asy}
import graph;
struct DblLine{
typedef pair T_fParam(real t);
guide gline,midLine,leftLine,rightLine;
arrowhead arrowHeadStyle;
guide arhd; // arrow head outline;
guide leftAr, rightAr;
pen leftPen, rightPen;
T_fParam fmid(guide g){return new pair(real t){return point(g,t);} ;}
T_fParam fleft(guide g,pen linepen=currentpen, real sc=linewidth(linepen)){
return new pair(real t){
pair m=point(g,t);
pair p=m+rotate(90)*scale(sc)*dir(g,t);
return p;
};
}
T_fParam fright(guide g,pen linepen=currentpen, real sc=linewidth(linepen)){
return new pair(real t){
pair m=point(g,t);
pair p=m+rotate(-90)*scale(sc)*dir(g,t);
return p;
};
}
void prepareHead(){
arhd=arrowHeadStyle.head(midLine,leftPen);
int midPointNo=ceil(size(arhd)/2);
leftAr=subpath(arhd,0,midPointNo)--cycle;
rightAr=subpath(arhd,midPointNo,size(arhd))--cycle;
}
void prepareLine(){
midLine=graph(fmid(gline),0.0,(real)size(gline),operator..);
leftLine=graph(fleft(gline,leftPen),0.0,(real)size(gline),operator..);
rightLine=graph(fright(gline,rightPen),0.0,(real)size(gline),operator..);
if(arrowHeadStyle!=null){
prepareHead();
leftLine=subpath(leftLine,0.0,intersect(leftLine,arhd)[0]);
rightLine=subpath(rightLine,0.0,intersect(rightLine,arhd)[0]);
}
}
void draw(){
fill(midLine--reverse(leftLine)--cycle,leftPen);
fill(rightLine--reverse(midLine)--cycle,rightPen);
if(arrowHeadStyle!=null){
fill(leftAr,leftPen);
fill(rightAr,rightPen);
}
}
void operator init(guide gline, arrowhead arrowHeadStyle=null,pen leftPen=red,pen rightPen=blue){
this.gline=gline;
this.arrowHeadStyle=arrowHeadStyle;
this.leftPen=leftPen;
this.rightPen=rightPen;
prepareLine();
}
}
////// Example of two-colored-line drawings:
//
// import twocoloredline;
// size(100);
// guide g=scale(0.5)*rotate(60)*shift(-100,-50)*((0,0)::(100,100){up}::(0,200){down});
// DblLine dblg=DblLine(shift(-20,-20)*scale(0.5)*g,blue,red); // blue/red line
// dblg.draw();
//
// DblLine(shift(-10,-5)*g, HookHead).draw();
//
// DblLine(shift(-100,-50)*((10,0)--(50,0)), HookHead,green+.4pt,blue).draw();
//
// DblLine(shift(-100,-50)*((10,0)--(0,50)), HookHead,red+0.2pt,green).draw();
//
//
// DblLine((-40,-40)..(0,-40){up}..{up}(0,-10)..(-40,-10), HookHead,green,lightred+0.2pt).draw();
\end{filecontents*}
\documentclass{article}
\usepackage{asymptote}
\begin{document}
\begin{asy}
// Example of two-colored-line drawings:
import twocoloredline;
size(100);
guide g=scale(0.5)*rotate(60)*shift(-100,-50)*((0,0)::(100,100){up}::(0,200){down});
DblLine dblg=DblLine(shift(-20,-20)*scale(0.5)*g,blue,red); // blue/red line
dblg.draw();
DblLine(shift(-10,-5)*g, HookHead).draw();
DblLine(shift(-100,-50)*((10,0)--(50,0)), HookHead,green+.4pt,blue).draw();
DblLine(shift(-100,-50)*((10,0)--(0,50)), HookHead,red+0.2pt,green).draw();
DblLine((-40,-40)..(0,-40){up}..{up}(0,-10)..(-40,-10), HookHead,green,lightred+0.2pt).draw();
\end{asy}
\end{document}
答案2
\documentclass{article}
\usepackage{xcolor}
\usepackage{verbatimbox}
\begin{document}
\shortstack{\addvbuffer[0ex -.72ex]{$\textcolor{red}{\leftharpoonup}$}\\
\addvbuffer[-.72ex 0ex]{$\textcolor{blue}{\leftharpoondown}$}}
\shortstack{\addvbuffer[0ex -.72ex]{$\textcolor{red}{\rightharpoonup}$}\\
\addvbuffer[-.72ex 0ex]{$\textcolor{blue}{\rightharpoondown}$}}
\end{document}