我怎样才能为一条(装饰过的)路径着色或者让它在穿过节点时消失?

我怎样才能为一条(装饰过的)路径着色或者让它在穿过节点时消失?

路径只是一条穿过节点然后分成三条的路径。当穿过包含文本的节点时,它应该变暗,或者甚至更好地向节点中心淡出,然后在离开节点时恢复其完整颜色。 等没有transparency帮助opacity

% uses-*- MODE: latex; TeX-engine: luatex; coding: utf-8; -*-
\documentclass[fontsize=10pt]{standalone}
\usepackage[main=latin]{babel}
\usepackage{fontspec}
\usepackage{tikz}
\usetikzlibrary{positioning, decorations.pathmorphing, arrows.meta,
  automata, decorations.pathreplacing, decorations.shapes,
  decorations.text, fadings, patterns}
\setmainfont{TeX Gyre Pagella X}
\begin{document}
\tikzset{x=.7cm,y=.7cm}
\begin{tikzpicture}
  \begin{scope}[align=center, every node/.style={draw, circle},>=stealth]
    \node(Cotta) at (5,5) {C.~Aurelius Cotta};
    \node(Balbus) at (0,0) {Q.~Lucilius Balbus};
    \node(Velleius) at (10,0)  {C.~Velleius};
    \node[minimum width=2](Cicero) at (5,-5) {M.~Tullius Cicero};
    \node[minimum width=2](Lector) at (5, -10) {Lector};
  \end{scope};
  \begin{scope}[every path/.style={black, decorate, decoration={waves}}]
    \draw (Lector) -- (5,-5);
    \draw (5,-5) -- (Balbus) ;
    \draw (5,-5) -- (Cotta) ;
    \draw (5,-5) -- (Velleius);
  \end{scope};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

以手册中的例子来说,您可以声明基于径向阴影的淡入淡出,而不是真实的使用占位符的颜色transparent

\tikzfading[name=fade out, inner color=transparent!0, outer color=transparent!100]

然后您可以path fading=fade out, fill=white在 Cicero 节点上使用:

\node[minimum width=2, path fading=fade out, fill=white]
  (Cicero) at (5, -5) {M.~Tullius Cicero};

波浪路径需要放在这个节点后面,在这种情况下,最简单的方法是通过库on background layer来完成backgrounds

如果你不喜欢这种褪色效果,我们需要通过以下方式实现另一种阴影\pgfdeclareradialshading或使用预定义的衰落circle with fuzzy edge XX percent,其中XX代表101520(相当刺耳)。

根据您的 PDF 渲染器,您可能会体验到不同的结果。

代码

% arara: lualatex
\documentclass[fontsize=10pt]{standalone}
\usepackage[main=latin]{babel}
\usepackage{fontspec}
\usepackage{tikz}
\usetikzlibrary{positioning, decorations.pathreplacing, backgrounds, fadings}
\setmainfont{TeX Gyre Pagella X}
\tikzfading[name=fade out, inner color=transparent!0, outer color=transparent!100]
\begin{document}
\tikzset{x=.7cm,y=.7cm}
\begin{tikzpicture}
\begin{scope}[align=center, every node/.style={draw, circle}]
\node(Cotta) at (5,5) {C.~Aurelius Cotta};
\node(Balbus) at (0,0) {Q.~Lucilius Balbus};
\node(Velleius) at (10,0)  {C.~Velleius};
\node[minimum width=2, path fading=fade out, fill=white] % ← add fading
  (Cicero) at (5, -5) {M.~Tullius Cicero};
\node[minimum width=2](Lector) at (5, -10) {Lector};
\end{scope};
\begin{scope}[
  every path/.style={decorate, decoration={waves}},
  on background layer] % ← on background
\draw (Lector) -- (Cicero.center);
\draw (Cicero.center) -- (Balbus) ;
\draw (Cicero.center) -- (Cotta) ;
\draw (Cicero.center) -- (Velleius);
\end{scope};
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容