I want to make an arrow that has gradual color as shown in the picture below:
First I wanted to make that arrow in one stroke, but I do not know how to make shaded color in postaction
, so in the end I draw right side first, left side second and put shade over it in the middle.
Now two problems appear.
- Color shading is not perfect, the middle colors do not correspond well to colors on the left and on the right. I found out that the problem comes from the fact I opened
xcolor
incmyk
mode. - The thickness of the colored part of the arrow is not perfectly constant. This cannot be seen on the picture but on the MWE-created PDF.
Is there any other way to create such effect, let's say in one stroke? If not, how can colors created by \draw
be aligned with colors created by \shade
?
IMPORTANT EDIT: I would prefer a tweak to the existing solution, if possible. Namely I am already using dozens of such arrows without color gradient going between two specified points following a bent path, i.e. (0,0) — (0.5,0) arc (-90:0:0.5) — (1,1). Now I just need ONE straight but with gradient color.
MWE:
\documentclass{minimal}
\usepackage[cmyk]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw[line width=4.15mm,{Triangle Cap[reversed,cap angle=120]}-,postaction={draw,color=red!75,line width=3.85mm,shorten <=0.25mm}] (0,0) -- (-0.8,0);
\draw[line width=4.15mm,-{Triangle Cap[cap angle=120]},postaction={draw,color=red!25,line width=3.85mm,shorten >=0.21mm}] (-0.8,0) -- (-1.6,0);
\shade[left color=red!25,right color=red!75] (-0.6,-0.5*3.85mm) rectangle (-1.0,0.5*3.85mm);
\end{tikzpicture}
\end{document}
Best Answer
Explanation
Relating to the question of this comment:
With the first approach you can also use
postaction
, butshading path
trims the arrow, concretely, in the case of the path(0,0) -- (0.5,0) arc (-90:0:0.5) -- (1,1)
(not in the others):Therefore, with an "overlapping" works well, because both arrows are trimmed.
With the second/third approach (third code version) you can pass other options such as
shading xsep=<length>
andshade path
sorts everything else out, see please the answer of Mark Wibrow:Of course you can also overlap with the second/third approach.
Third approach, with improved
postaction
:The next improvements are based on the comment of marmot, see below:
Output
shading1
:Output
shading2
:Code:
Second approach, with
postaction
:With the third version of the answer 1 is also possible to achieve the same result with
postaction
:Output
shading1
:Output
shading2
:Code:
First approach, with "overlapping":
Based on this answer to tikz: draw multicolor curve with smooth gradient, which relies on other two (1,2) given by Mark Wibrow, you can also achieve a color gradient with the
shaping path
and the commands of the Shading library (Chapter 69, p.737):left color=<color>
andright color=<color>
(ortop color=<color>
andbottom color=<color>
).For a multicolor gradient, you can define:
Output
shading1
:Output
shading2
:Code:
TODO: