2

I have the following line using \draw (see MWE below). I would like to have the line change in color, from red on the right, to blue on the left. Current attempts are adding a fading region rather than changing the color of the line itself.

Note that this solution by percusse offers a solution, using a custom fade, but I'm not sure how to edit it to get the effect I'm looking for. I would ideally like to add an edit to \draw[...] that achieves this effect.

MWE

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture} \draw [ultra thick,red] (-19.5,-16) to[out=55,in=228] (-14,-9) to [out=45,in=180] (0,-2) to[out=0,in=135] (14, -9) to[out=315,in=125] (20,-16);
\end{tikzpicture}

\end{document}

Sid
  • 1,806

1 Answers1

1

If you want it shaded I have a (dirty) but quick solution. Use shade and add a filled white version in front:

\documentclass[tikz,border=1cm]{standalone}

\pgfdeclarelayer{background} \pgfdeclarelayer{foreground} \pgfsetlayers{background,main,foreground}

\begin{document}

\begin{tikzpicture} \fill[fill=white] (-19.35,-16.01) to[out=55,in=228] (-13.8,-9) to [out=45,in=180] (0,-2.15) to[out=0,in=135] (13.8, -9) to[out=315,in=125] (19.85,-16.01);

\begin{pgfonlayer}{background} 
        \shade[left color=blue, right color=red, very thick] (-19.5,-16) to[out=55,in=228] (-14,-9) to [out=45,in=180] (0,-2) to[out=0,in=135] (14, -9) to[out=315,in=125] (20,-16);  
    \end{pgfonlayer} 

\end{tikzpicture}

\end{document}

This is the effect I think you are looking for without any custom fading. enter image description here

Roland
  • 6,655
  • The later answer was indeed what I was looking for – Sid Jul 13 '21 at 08:54
  • Is it possible to add a left opacity and right opacity? I'm looking for a bit more control that path fading=west. Something that controls where the fading/opacity starts – Sid Jul 13 '21 at 10:22