我想将下面的两个图形合并为一个。即有一个箭头,颜色从底部的红色变为顶部的蓝色。有人能告诉我怎么做吗?
答案1
尝试制作“色条”样式阴影的问题在于,在将阴影拟合到路径的过程中,PGF 会缩放阴影,以便只能看到阴影的中心四分之一(请参阅手册中的“使用阴影”)。
这意味着要么必须将颜色条“挤压”到阴影定义的中心四分之一,这手动操作很麻烦,要么必须剪切要着色的路径并手动缩放,这也会有点麻烦。
下面显示了一种使用命名颜色列表指定颜色条(假定占据条的相同宽度)并自动生成(或多或少)适当的阴影的方法:
\documentclass[tikz, border=5]{standalone}
\usetikzlibrary{shapes.arrows}
\makeatletter
\def\createshadingfromlist#1#2#3{%
\pgfutil@tempcnta=0\relax
\pgfutil@for\pgf@tmp:={#3}\do{\advance\pgfutil@tempcnta by1}%
\ifnum\pgfutil@tempcnta=1\relax%
\edef\pgf@spec{color(0)=(#3);color(100)=(#3)}%
\else%
\pgfmathparse{50/(\pgfutil@tempcnta-1)}\let\pgf@step=\pgfmathresult%
%
\pgfutil@tempcntb=1\relax%
\pgfutil@for\pgf@tmp:={#3}\do{%
\ifnum\pgfutil@tempcntb=1\relax%
\edef\pgf@spec{color(0)=(\pgf@tmp);color(25)=(\pgf@tmp)}%
\else%
\ifnum\pgfutil@tempcntb<\pgfutil@tempcnta\relax%
\pgfmathparse{25+\pgf@step/4+(\pgfutil@tempcntb-1)*\pgf@step}%
\edef\pgf@spec{\pgf@spec;color(\pgfmathresult)=(\pgf@tmp)}%
\else%
\edef\pgf@spec{\pgf@spec;color(75)=(\pgf@tmp);color(100)=(\pgf@tmp)}%
\fi%
\fi%
\advance\pgfutil@tempcntb by1\relax%
}%
\fi%
\csname pgfdeclare#2shading\endcsname{#1}{100}\pgf@spec%
}
\createshadingfromlist{shading1}{vertical}{red,yellow,green,cyan,blue}
\createshadingfromlist{shading2}{vertical}{red,yellow}
\createshadingfromlist{shading3}{vertical}{black,blue,cyan,white}
\begin{document}
\begin{tikzpicture}[colorbar arrow/.style={
shape=double arrow,
double arrow head extend=0.125cm,
shape border rotate=90,
minimum height=5cm,
shading=#1
}]
\node [colorbar arrow=shading1] at (0,0) {};
\node [colorbar arrow=shading2] at (1,0) {};
\node [colorbar arrow=shading3] at (2,0) {};
\end{tikzpicture}
\end{document}
答案2
一个 PSTricks 示例。运行它xelatex
\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pstricks-add,pst-slpe}
\begin{document}
\begin{pspicture}(9,10)
\psset{doublesep=1cm}
\psBigArrow[fillstyle=slope,slopebegin=cyan!100!white!80,slopeend=black,slopeangle=0](1,0)(1,10)
\psBigArrow[fillstyle=slope,slopebegin=red,slopeend=blue,slopeangle=0](4,0)(4,10)
\psBigArrow[fillstyle=slope,slopebegin=red,slopeend=green,slopeangle=0](7,0)(7,10)
\end{pspicture}
\end{document}