6

I’m trying to have colour gradient on path, and discovered fade-no-fill.sty, which latest version seems to be https://tex.stackexchange.com/a/567029/56823. It works pretty well, but I have two small issues.

My MWE is as follow:

\documentclass[tikz]{standalone}

\usepackage{fade-no-fill} \usetikzlibrary{shapes}

\begin{document} \begin{tikzpicture} \pgfmathsetmacro{\l}{3} \node [red,draw,thick,ellipse] (S) at (-\l,0) {Solide}; \node [blue,draw,thick,ellipse] (L) at (\l,0) {Liquide}; \node [green,draw,thick,ellipse] (G) at (0,{\l*sqrt(3)}) {Gaz}; \path [fade path but don't fill={thick,->,>=latex,transparent!0}{bottom color=red,top color=green}] (S) to[bend left] (G); \path [fade path but don't fill={thick,->,>=latex,transparent!0}{top color=green,bottom color=blue}] (G) to[bend left] (L); \path [fade path but don't fill={thick,->,>=latex,transparent!0}{right color=blue,left color=red}] (L) to[bend left] (S); \path [fade path but don't fill={thick,->,>=latex,transparent!0}{left color=red,right color=blue}] (S) to (L); \path [fade path but don't fill={thick,->,>=latex,transparent!0}{top color=green,bottom color=blue}] (L) to (G); \path [fade path but don't fill={thick,->,>=latex,transparent!0}{bottom color=red,top color=green}] (G) to (S); \end{tikzpicture} \end{document}

It produces this: MWE output Note:

  1. the clipped blue arrow above “Liquide”.
  2. the very strange arrow at the left of “Liquide”.

Any idea what could be causing this and how to solve it?

Archange
  • 1,368
  • Try adding \usetikzlibrary{bending} – Ross Sep 17 '21 at 14:14
  • Have you tried suggestion from @Ross? (I do not know what it does, but try it) Also add \usetikzlibrary{arrows.meta} "% needed so that bounding boxes correctly include arrows." (should already be in fade-no-fill.sty - but try it) – hpekristiansen Sep 17 '21 at 21:27
  • Try this (maybe it will expand the bounding box) \path [fade path but don't fill={thick,->,>=latex,transparent!0}{top color=green,bottom color=blue}] (G) to[bend left] (L) edge[draw=none] ([turn] 90:0.2); – hpekristiansen Sep 17 '21 at 21:37
  • There is another fading question, where the arrowhead gets cut of - maybe you can draw the head separately like here: https://tex.stackexchange.com/a/597939/8650 – hpekristiansen Sep 17 '21 at 21:39
  • 1
    It is almost certainly an issue with the arrowheads not being included in the bounding box calculations. If you imagine a rectangle around each path then you can see why they get flipped but the others don't. – Andrew Stacey Sep 17 '21 at 22:09
  • @AndrewStacey: Yes. In a normal path fading, it looks like the bounding box is doubled(but apparently not here) so that only when lines are near horizontal/vertical arrow heads are clipped. https://tex.stackexchange.com/q/597927/8650 – hpekristiansen Sep 18 '21 at 00:03
  • @Ross solution does nothing, but this is indeed definitively a clipping issue. – Archange Sep 18 '21 at 04:43
  • @hpekristiansen I’ve indeed figured out a solution redrawing the arrows head that I’ve added as a solution just before you’ve posted this comment. I’m now looking into the other ones proposed since. – Archange Sep 18 '21 at 04:45

4 Answers4

6

Here is another methode where all the arrows are drawn twice with two different colors path fading from different directions.

\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{shapes, fadings}
\begin{document}
\begin{tikzpicture}
\node[red,draw,thick,ellipse] (S) at (-3,0) {Solide};
\node[blue,draw,thick,ellipse] (L) at (3,0) {Liquide};
\node[green,draw,thick,ellipse] (G) at (0,{3*sqrt(3)}) {Gaz};
\draw[green, path fading=south, thick ,-latex] (S) to[bend left] (G);
\draw[red, path fading=north, thick ,-latex] (S) to[bend left] (G);
\draw[green, path fading=south, thick ,-latex] (G) to[bend left] (L);
\draw[blue, path fading=north, thick ,-latex] (G) to[bend left] (L);
\draw[blue, path fading=west, thick ,-latex] (L) to[bend left] (S);
\draw[red, path fading=east, thick ,-latex] (L) to[bend left] (S);
\draw[blue, path fading=west, thick, shorten >=5pt] (S) to (L); %this arror is problematic
\draw[blue, thick ,-latex] ([xshift=-4pt] L.west) -- (L.west); %seperate arrow head
\draw[red, path fading=east, thick ,-latex] (S) to (L);
\draw[green, path fading=south, thick ,-latex] (L) to (G);
\draw[blue, path fading=north, thick ,-latex] (L) to (G);
\draw[green, path fading=south, thick ,-latex] (G) to (S);
\draw[red, path fading=north, thick ,-latex] (G) to (S);
\end{tikzpicture}
\end{document}

Diagram with color fading arrows

The horizontal blue arrow head gets clipped, but is redrawn. A more universal method is here: https://tex.stackexchange.com/a/597939/8650

Edit:

The double drawing can be made into a style with a postaction here is a start:

\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{fadings, calc}
\begin{document}
\begin{tikzpicture}   
\foreach \a in {0,10,...,360}{
\coordinate (A) at (0,0);
\coordinate (B) at (\a:3);
\draw let \p1=($(B)-(A)$), \n1={atan2(\y1,\x1)} in [green, path fading=west, fading angle = \n1, thick ,-latex, postaction={draw, red, path fading=east, fading angle = \n1, thick ,-latex}]  ([xshift=5pt, yshift=5pt]A) (A) to[bend left] (B);
}
\end{tikzpicture}
\end{document}

Red and green arrow wheel

  • This is a very nice solution and I might actually switch to that, however I’ve accepted @symbol-1 solution since it properly fixes the clipping answer in the context of the question (using fade-no-fill). But I’ve upvoted you on https://tex.stackexchange.com/a/615816/56823 ;) – Archange Sep 18 '21 at 04:52
  • I agree Symbol1 answered your question. (but this is probably a nicer solution) – hpekristiansen Sep 18 '21 at 04:55
  • Actually it’s not just the arrow that gets clipped, see https://tex.stackexchange.com/q/615945/56823 – Archange Sep 19 '21 at 09:13
6

> = latex is an arrow tip without bounding box. (This arrow head is defined in pgfcorearrows.code.tex and is available regardless of whether arrows.meta is included.)

With > = Latex, the arrow tip has a bounding box. (This arrow head is defined in arrows.meta with proper bounding box.)

Symbol 1
  • 36,855
  • Cool. Do you know why it goes wrong for the normal -> here: https://tex.stackexchange.com/q/597927/8650 ? – hpekristiansen Sep 18 '21 at 03:26
  • 1
    I also answered that question =P. It has something to do with the order of computation. (fading comes before adding arrow heads.) – Symbol 1 Sep 18 '21 at 03:29
  • 1
    Wow - You effortlessly jumped back in time and answered, just to make me look stupid :o) – hpekristiansen Sep 18 '21 at 03:39
  • (dummy parentheses to meet mim char requirement) – Symbol 1 Sep 18 '21 at 03:48
  • Interesting, good to know. I’m accepting this answer since this is the one correctly solving clipping while using fade-no-fill, but @hpekristiansen new solution with twice drawing is also nice to work without fade-no-fill. :) – Archange Sep 18 '21 at 04:49
4

Since we are into workarounds, I’ve tried this one:

\documentclass[tikz]{standalone}

\usepackage{fade-no-fill} \usetikzlibrary{shapes}

\begin{document} \begin{tikzpicture} \pgfmathsetmacro{\l}{3} \node [red,draw,thick,ellipse] (S) at (-\l,0) {Solide}; \node [blue,draw,thick,ellipse] (L) at (\l,0) {Liquide}; \node [green,draw,thick,ellipse] (G) at (0,{\l*sqrt(3)}) {Gaz}; \path [fade path but don't fill={thick,->,>=latex,transparent!0}{bottom color=red,top color=green}] (S) to[bend left] (G); \path [fade path but don't fill={thick,->,>=latex,transparent!0}{top color=green,bottom color=blue}] (G) to[bend left] (L); \path [fade path but don't fill={thick,->,>=latex,transparent!0}{right color=blue,left color=red}] (L) to[bend left] (S); \path [fade path but don't fill={thick,->,>=latex,transparent!0}{left color=red,right color=blue}] (S) to (L); \path [fade path but don't fill={thick,->,>=latex,transparent!0}{top color=green,bottom color=blue}] (L) to (G); \path [fade path but don't fill={thick,->,>=latex,transparent!0}{bottom color=red,top color=green}] (G) to (S); \draw [thick,<-,>=latex,blue] (L.west) -- ++(-0.1,0); % Redraw west arrow \draw [thick,<-,>=latex,blue] (L.north) -- ++(0,0.1); % Redraw north arrow \end{tikzpicture} \end{document}

Result with workaround The result suits me, but this is still a workaround nonetheless.

Archange
  • 1,368
3

I do not know \usepackage{fade-no-fill}, but here is an alternative solution using tikzfadingfrompicture:

\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{shapes, fadings, shadings}
\begin{tikzfadingfrompicture}[name=myfading]
\pgfmathsetmacro{\l}{3}
\node[transparent!0,draw,thick,ellipse] (S) at (-\l,0) {Solide};
\node[transparent!0,draw,thick,ellipse] (L) at (\l,0) {Liquide};
\node[transparent!0,draw,thick,ellipse] (G) at (0,{\l*sqrt(3)}) {Gaz};
\draw[transparent!0, thick ,-latex] (S) to[bend left] (G);
\draw[transparent!0, thick ,-latex] (G) to[bend left] (L);
\draw[transparent!0, thick ,-latex] (L) to[bend left] (S);
\draw[transparent!0, thick ,-latex] (S) to (L);
\draw[transparent!0, thick ,-latex] (L) to (G);
\draw[transparent!0, thick ,-latex] (G) to (S);
\end{tikzfadingfrompicture}
\begin{document}
\begin{tikzpicture}
\draw[lower left=red, lower right=blue, upper left=green, upper right=green, path fading=myfading, fit fading=false] (-3.9,-3.3) rectangle (4.1,3.5);
\end{tikzpicture}
\end{document}

Three nodes with color faded arrows

Edit:

I just got an idea of how to prevent translation of the tikzfadingfrompicture - simply add a circle centered at (0,0) that encompasses everything.

\draw[transparent!100] (0,0) circle (6);. Now the nodes can be drawn outside the fading, if so desired:

Same graph, but with mono colored nodes

\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{shapes, fadings, shadings}
\begin{tikzfadingfrompicture}[name=myfading]
\node[transparent!100,draw,thick,ellipse] (S) at (-3,0) {Solide};
\node[transparent!100,draw,thick,ellipse] (L) at (3,0) {Liquide};
\node[transparent!100,draw,thick,ellipse] (G) at (0,{3*sqrt(3)}) {Gaz};
\draw[transparent!0, thick ,-latex] (S) to[bend left] (G);
\draw[transparent!0, thick ,-latex] (G) to[bend left] (L);
\draw[transparent!0, thick ,-latex] (L) to[bend left] (S);
\draw[transparent!0, thick ,-latex] (S) to (L);
\draw[transparent!0, thick ,-latex] (L) to (G);
\draw[transparent!0, thick ,-latex] (G) to (S);
\draw[transparent!100] (0,0) circle (6);
\end{tikzfadingfrompicture}
\begin{document}
\begin{tikzpicture}
\draw[lower left=red, lower right=blue, upper left=green, upper right=green, path fading=myfading, fit fading=false] (-4,-1.2) rectangle (4.1,5.8);
\node[red,draw,thick,ellipse] (S) at (-3,0) {Solide};
\node[blue,draw,thick,ellipse] (L) at (3,0) {Liquide};
\node[green,draw,thick,ellipse] (G) at (0,{3*sqrt(3)}) {Gaz};
\end{tikzpicture}
\end{document}
  • 2
    Wow! This is very interesting. I didn't know about this tikzfadingfrompicture environment. I'll dig into it (since it's in the manual). – SebGlav Sep 17 '21 at 18:00
  • 3
    @SebGlav I find it difficult to work with and not well described. fit fading=false prevents scaling of the fading picture, but there will be a translation. I unsuccessfully tried to have the nodes outside the fading, but I can not make the placement predictable. – hpekristiansen Sep 17 '21 at 18:09
  • @SebGlav: Ok - I guess, that I now have an idea, of how to hack the translation. – hpekristiansen Sep 17 '21 at 18:45
  • This is an interesting alternative, but unfortunately I indeed don’t want nodes inside the fading, and your solution doing that is having issues with colour gradient not ending with the node colour (since they still take the ellipses into account). I guess I could hack something using a fadingfrompicture for each of the arrow? – Archange Sep 17 '21 at 20:29