我从以下代码开始:
\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}
我对阴影曲线(\path
示例中的最后一条)很感兴趣,从红色到洋红色再到蓝色(我已经包含了其他的,\path
这样你就能明白我为什么对此感兴趣)。
注释掉的部分显示了我对此如何工作的最佳猜测,但当然不是。我花了一些时间浏览 TeX.SX,我看到了一些看起来相关的解决方案,但似乎没有一个能直接解决这个问题。
答案1
我可能说得太早了。
Mark Wibrow 的解决方案似乎适用。
输出
已应用 Mark 的代码
\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}