1

I'm starting with the following code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows.meta, matrix}

\begin{document}

\begin{tikzpicture}[description/.style={fill=white,inner sep=1.5pt}]
  \matrix (m) [%
    matrix of math nodes,
    row sep=8em, column sep=8em,
    text height=1.5ex,
    text depth=0.25ex
  ]{
    (a \rightarrow t) \rightarrow t & a & (a \rightarrow S b) \rightarrow S b
    \\
    & S a &
    \\
  };
  \path[-stealth,font=\scriptsize, red]
    (m-1-2) edge node[description] {LIFT$_t$} (m-1-1)
    (m-2-2) edge node[sloped,description] {A} (m-1-1);
  \path[-stealth,font=\scriptsize, blue]
    (m-1-2) edge node[description] {LIFT$_{S b}$} (m-1-3)
    (m-2-2) edge node[sloped,description] {BIND} (m-1-3);
  \path[-stealth,font=\scriptsize, magenta]
    (m-1-2) edge node[description] {$\eta$} (m-2-2);
  \path[-stealth,font=\scriptsize%, left color=red, right color=blue
    ]
    (m-1-1) edge[bend left=25] node[pos=.75,sloped,description]
    {Cresti's [+WH]} (m-1-3);
\end{tikzpicture}

\end{document}

I am interested in shading the curving line (the final \path in the example), from red to magenta to blue (I've included the other \path's so you can see why I might be interested in this).

The commented-out portion shows my best guess at how this would work, but of course it doesn't. I've spent some time browsing TeX.SX, and I've seen some solutions that look related, but nothing that seems to directly address this.

SEC
  • 761
  • Possibly related http://tex.stackexchange.com/questions/20540/line-with-transparence-changing-with-tikz – JLDiaz Jan 23 '17 at 18:48
  • Also related : http://tex.stackexchange.com/questions/134283/tikz-shading-a-path-without-any-filling – marsupilam Jan 23 '17 at 18:49
  • Thanks, I am aware of both. They don't seem directly applicable (at least not obviously so): the first addresses shading but not color gradation, and the second actually doesn't give the reported output in an up-to-date tikz setup (the arrow head is missing, for example). – SEC Jan 23 '17 at 19:07
  • Also this, which looks to me like what you want http://tex.stackexchange.com/a/141551/116936 – marsupilam Jan 23 '17 at 19:17
  • Have you ever tried fadings library. It does sound the thing you required... –  Jan 23 '17 at 19:18
  • 1
    And this, from 2016 : http://tex.stackexchange.com/a/315342/116936 – marsupilam Jan 23 '17 at 19:19
  • But as you pointed, these solutions are not very satisfactory. So the short answer to your question is : what you want to do is not (yet) supported by TikZ. – marsupilam Jan 23 '17 at 19:30
  • 1
    Interesting. The last one posted comes closest, but it's not clear how to integrate it with nodes defined in the matrix (which the tikzfadingfrompicture environment cannot see). – SEC Jan 23 '17 at 19:32

1 Answers1

2

Maybe I spoke too soon.

Mark Wibrow's solution seems to apply.

The output

enter image description here

Mark's code applied

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fadings,decorations.pathmorphing,arrows.meta,matrix,calc}


\makeatletter
% Code by Mark Wibrow 
% https://tex.stackexchange.com/a/137438/116936
% solution 2
\newif\iftikz@shading@path

\tikzset{
    % There are three circumstances in which the fading sep is needed:
    % 1. Arrows which do not update the bounding box (which is most of them).
    % 2. Line caps/joins and mitres that extend outside the natural bounding 
    %    box of the path (these are not calculated by PGF).
    % 3. Other reasons that haven't been anticipated.
    fading xsep/.store in=\pgfpathfadingxsep,
    fading ysep/.store in=\pgfpathfadingysep,
    fading sep/.style={fading xsep=#1, fading ysep=#1},
    fading sep=0.0cm,
    shading path/.code={%
        % Prevent this stuff happning recursively.
        \iftikz@shading@path%
        \else%
            \tikz@shading@pathtrue%
            % \tikz@addmode installs the `modes' (e.g., fill, draw, shade) 
            % to be applied to the path. It isn't usualy for doing more
            % changes to the path's construction.
            \tikz@addmode{%
                \pgfgetpath\pgf@currentfadingpath%
                % Get the boudning box of the current path size including the fading sep
                \pgfextract@process\pgf@fadingpath@southwest{\pgfpointadd{\pgfqpoint{\pgf@pathminx}{\pgf@pathminy}}%
                    {\pgfpoint{-\pgfpathfadingxsep}{-\pgfpathfadingysep}}}%%
                \pgfextract@process\pgf@fadingpath@northeast{\pgfpointadd{\pgfqpoint{\pgf@pathmaxx}{\pgf@pathmaxy}}%
                    {\pgfpoint{\pgfpathfadingxsep}{\pgfpathfadingysep}}}%
                % Clear the path
                \pgfsetpath\pgfutil@empty%                          
                % Interrupt the path and picture to create a fading.
                \pgfinterruptpath%
                \pgfinterruptpicture%
                    \begin{tikzfadingfrompicture}[name=.]
                        \path [shade=none,fill=none, #1] \pgfextra{%
                            % Set the softpath. Any transformations in #1 will have no effect.
                            % This will *not* update the bounding box...
                            \pgfsetpath\pgf@currentfadingpath%
                            % ...so it is done manually.
                            \pgf@fadingpath@southwest
                            \expandafter\pgf@protocolsizes{\the\pgf@x}{\the\pgf@y}%
                            \pgf@fadingpath@northeast%
                            \expandafter\pgf@protocolsizes{\the\pgf@x}{\the\pgf@y}%
                        };
                        % Now get the bounding of the picture.
                        \xdef\pgf@fadingboundingbox@southwest{\noexpand\pgfqpoint{\the\pgf@picminx}{\the\pgf@picminy}}%
                        \xdef\pgf@fadingboundingbox@northeast{\noexpand\pgfqpoint{\the\pgf@picmaxx}{\the\pgf@picmaxy}}%
                        %
                    \end{tikzfadingfrompicture}%
                \endpgfinterruptpicture%
                \endpgfinterruptpath%
                % Install a rectangle that covers the shaded/faded path picture.                                
                \pgfpathrectanglecorners{\pgf@fadingboundingbox@southwest}{\pgf@fadingboundingbox@northeast}%
                % Make the fading happen.
                \def\tikz@path@fading{.}%
                \tikz@mode@fade@pathtrue%
                \tikz@fade@adjustfalse%10pt
                % Shift the fading to the mid point of the rectangle
                \pgfpointscale{0.5}{\pgfpointadd{\pgf@fadingboundingbox@southwest}{\pgf@fadingboundingbox@northeast}}%
                \edef\tikz@fade@transform{shift={(\the\pgf@x,\the\pgf@y)}}%
            }%
        \fi%
    }
}

\begin{document}
\begin{tikzpicture}[description/.style={fill=white,inner sep=1.5pt}]
  \matrix (m) 
    [%
      matrix of math nodes,
      row sep=8em, column sep=8em,
      text height=1.5ex,
      text depth=0.25ex
    ]
    {
    (a \rightarrow t) \rightarrow t & a   & (a \rightarrow S b) \rightarrow S b \\
                                    & S a &                                     \\
  };
  \path[-stealth,font=\scriptsize, red]
    (m-1-2) edge node[description] {LIFT$_t$} (m-1-1)
    (m-2-2) edge node[sloped,description] {A} (m-1-1);
  \path[-stealth,font=\scriptsize, blue]
    (m-1-2) edge node[description] {LIFT$_{S b}$} (m-1-3)
    (m-2-2) edge node[sloped,description] {BIND} (m-1-3);
  \path[-stealth,font=\scriptsize, magenta]
    (m-1-2) edge node[description] {$\eta$} (m-2-2);
    \def\height{2}
  \path
    [
    left color=red,
    right color=blue,
    shading path={draw=transparent!0,stealth-stealth,},
    ]
    (m-1-1) .. controls ($(m-1-1)!.3!(m-1-3)+(0,\height)$) and ($(m-1-1)!.7!(m-1-3)+(0,\height)$) .. (m-1-3) ;
    %and now for the label
    \path (m-1-1) .. controls ($(m-1-1)!.3!(m-1-3)+(0,\height)$) and ($(m-1-1)!.7!(m-1-3)+(0,\height)$) .. (m-1-3) node [pos=.7,sloped, fill = white, font=\scriptsize, yshift=-1pt ] {Cresti's [+WH]} ; 
\end{tikzpicture}
\end{document}
marsupilam
  • 6,383
  • Looks great. Unfortunately, doesn't play nicely with externalization, but that may be unavoidable. – SEC Jan 23 '17 at 20:31