我在网络图的径向图中用颜色渐变给一些路径上了颜色。我在 2020 年 1 月编写的文档的图片显示了它应该是这样的:
为了达到这个效果我使用了如何使用 spath3 包来为路径着色?。原始问题可以在这里找到:Tikz:对路径进行着色而不进行任何填充
在过去的几个月里,我没有编译过这个文档,但错误地更新了我的 LaTeX 安装。现在,当我编译它时,我得到(在调试模式下显示节点 ID 和边缘 ID 而不是标签):
如您所见,边缘e007
的形状与 相同,e002
但情况不应该如此。据我了解,第一条具有样式的路径fade no fill
被复制到所有其他路径。
我不想分享我的完整文档,但我认为遵循 MWE 的使用fade-no-fill.sty
也可以说明这一点:
\documentclass[tikz,border=5mm]{standalone}
\usepackage{fade-no-fill}
% rputover {{{1
% –––––––––––––––––
% https://tex.stackexchange.com/a/457885/8917
\makeatletter
\tikzset{
use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\tikzset{remember path/.style={save path=\tmprotect}}
\tikzset{reverseclip/.style={insert path={(current bounding box.north
east) rectangle (current bounding box.south west)}}%
}
\begin{document}
\begin{tikzpicture}
% PATH 1
\draw (0cm,-2cm) -- (1cm,0cm);
% PATH 2
\begin{scope}
\node[remember path,font=\Large\sf] at (0.5cm,-1cm) {label};
\clip[use path=\tmprotect,reverseclip];
% PATH 2
\path[
% draw=blue,
fade path but don't fill={ very thick, transparent!20, ->, }{top color=blue!80, bottom color=green!80,},
] (0cm,0cm) .. controls +(0cm,-1cm) and +(0cm,1cm) .. (1cm,-2cm);
% PATH 3
\end{scope}
\path[
% draw=red,
fade path but don't fill={ very thick, transparent!20, ->, }{ top color=blue!80, bottom color=green!80, },
] (1cm,1cm) -- (2cm,-1cm);
% PATH 4
\draw (-3cm,-2cm) -- (1cm,0cm);
\end{tikzpicture}
\end{document}
第二条路径再次令人惊讶地变成了一条贝塞尔曲线,它实际上是一条直线
有人知道哪个包发生了变化以及如何解决它吗?自 2019 年初以来,spath3 包似乎没有变化。我猜 pgf/tikz 发生了一些变化。
答案1
这个答案采用了 Ulrike Fischer 在问题评论中的建议:
修改的fade-no-fill.sty
:
%\url{https://tex.stackexchange.com/a/327713/86}
\usetikzlibrary{math}%
\usetikzlibrary{fadings}%
\usepackage{spath3}
\usetikzlibrary{arrows.meta}% needed so that bounding boxes correctly include arrows.
\ExplSyntaxOn
\cs_if_exist:NF \spath_set_current_softpath:n {
\cs_new_protected_nopar:Npn \spath_set_current_softpath:n #1
{
\spath_get:nnN {#1} {min bb} \l__spath_tmpa_tl
\exp_last_unbraced:NV \pgf@protocolsizes\l__spath_tmpa_tl
\spath_get:nnN {#1} {max bb} \l__spath_tmpa_tl
\exp_last_unbraced:NV \pgf@protocolsizes\l__spath_tmpa_tl
\spath_get:nnN {#1} {path} \l__spath_tmpa_tl
\pgfsyssoftpath@setcurrentpath\l__spath_tmpa_tl
}
}
\tikzset{restore~ soft~ path/.code={%
\spath_set_current_softpath:n {#1}
}
}
\ExplSyntaxOff
\makeatletter
\newcount\pgf@fadingboxcnt
\tikzset{
fade path but don't fill/.style 2 args={
preaction={save spath=fadingpath,},
postaction={
/utils/exec={
\coordinate (oldbb-ne) at (current bounding box.north east);
\coordinate (oldbb-sw) at (current bounding box.south west);
\pgfresetboundingbox
\global\advance \pgf@fadingboxcnt by 1
\begin{tikzfadingfrompicture}[name=tempfade\the\pgf@fadingboxcnt]%
\pgfresetboundingbox
\draw[restore soft path=fadingpath,#1];
\coordinate (temp-fade-bb-ne) at (current bounding box.north east);
\coordinate (temp-fade-bb-sw) at (current bounding box.south west);
\coordinate (temp-fade-bb-center) at (current bounding box.center);
\end{tikzfadingfrompicture}
%
\useasboundingbox (oldbb-ne) rectangle (oldbb-sw);
%
\tikzmath{
coordinate \ctempfadebbcenter;
\ctempfadebbcenter = (temp-fade-bb-center);
}
\tikzset{tempstyle/.style/.expand once={#2}}
\path[
path fading=tempfade\the\pgf@fadingboxcnt,
fit fading=false,
fading transform={
yshift=\ctempfadebbcentery,
xshift=\ctempfadebbcenterx,
},
tempstyle,
] (temp-fade-bb-ne) rectangle (temp-fade-bb-sw);
},
},
},
}
\makeatother
修改后,fade-no-fill.sty
发布的 MWE 给出了预期的结果:
由 Andrew Stacey 于 2021-07-13 更新fade-no-fill.sty
:自从编写了 的上一个版本以来,该spath3
库经历了一次重大更新。以下是 的一个版本,fade-no-fill.sty
它结合了此问题的解决方案以及使用 的最新版本的更新spath3
:
%\url{https://tex.stackexchange.com/a/327713/86}
\usetikzlibrary{math}%
\usetikzlibrary{fadings}%
\usetikzlibrary{spath3}
\usetikzlibrary{arrows.meta}% needed so that bounding boxes correctly include arrows.
\newcount\pgf@fadingboxcnt
\tikzset{
fade path but don't fill/.style 2 args={
preaction={spath/save global=fadingpath,},
postaction={
/utils/exec={
\coordinate (oldbb-ne) at (current bounding box.north east);
\coordinate (oldbb-sw) at (current bounding box.south west);
\pgfresetboundingbox
\global\advance \pgf@fadingboxcnt by 1\relax
\begin{tikzfadingfrompicture}[name=tempfade\the\pgf@fadingboxcnt]%
\pgfresetboundingbox
\draw[spath/use=fadingpath,#1];
\coordinate (temp-fade-bb-ne) at (current bounding box.north east);
\coordinate (temp-fade-bb-sw) at (current bounding box.south west);
\coordinate (temp-fade-bb-center) at (current bounding box.center);
\end{tikzfadingfrompicture}
%
\useasboundingbox (oldbb-ne) rectangle (oldbb-sw);
%
\tikzmath{
coordinate \ctempfadebbcenter;
\ctempfadebbcenter = (temp-fade-bb-center);
}
\tikzset{tempstyle/.style/.expand once={#2}}
\path[
path fading=tempfade\the\pgf@fadingboxcnt,
fit fading=false,
fading transform={
yshift=\ctempfadebbcentery,
xshift=\ctempfadebbcenterx,
},
tempstyle,
] (temp-fade-bb-ne) rectangle (temp-fade-bb-sw);
},
},
},
}
我将它添加到这个答案中而不是将它作为单独的答案,因为它没有给这个特定问题带来任何新内容,并且我没有更改原始代码,因为在撰写本文时,仍然有可能存在使用旧版本的安装spath3
。