优雅的修改方式\.阴影颜色代码

优雅的修改方式\.阴影颜色代码

尝试使用shadows.blur库为阴影添加颜色,我有一个方法,包括修改代码render blur shadow,这里是 MWE

\documentclass[margin=2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows.blur}

\makeatletter
\tikzset{render blur shadow/.code=
{\pgfbs@savebb
\pgfsyssoftpath@getcurrentpath{\pgfbs@input@path}%
\pgfbs@compute@shadow@bbox
\pgfbs@process@rounding{\pgfbs@input@path}{\pgfbs@fadepath}%
\pgfbs@apply@canvas@transform
\colorlet{pstb@shadow@color}{white!\pgfbs@opacity!violet}%
\pgfdeclarefading{shadowfading}{\pgfbs@paint@fading}%
\pgfsetfillcolor{violet}%
\pgfsetfading{shadowfading}%
{\pgftransformshift{\pgfpoint{\pgfbs@midx}{\pgfbs@midy}}}%
\pgfbs@usebbox{fill}%
\pgfbs@restorebb
},
}
\makeatother

\begin{document}

\begin{tikzpicture}
\node[fill=white, draw=black, blur shadow,font=\Large] {Node};
\end{tikzpicture}

\end{document} 

在此处输入图片描述

的原始定义render blur shadow

render blur shadow/.code=
    {\pgfbs@savebb
    \pgfsyssoftpath@getcurrentpath{\pgfbs@input@path}%
    \pgfbs@compute@shadow@bbox
    \pgfbs@process@rounding{\pgfbs@input@path}{\pgfbs@fadepath}%
    \pgfbs@apply@canvas@transform
    \colorlet{pstb@shadow@color}{white!\pgfbs@opacity!black}%
    \pgfdeclarefading{shadowfading}{\pgfbs@paint@fading}%
    \pgfsetfillcolor{black}%
    \pgfsetfading{shadowfading}%
    {\pgftransformshift{\pgfpoint{\pgfbs@midx}{\pgfbs@midy}}}%
    \pgfbs@usebbox{fill}%
    \pgfbs@restorebb
    }

从上面的代码我只是想用一种简单的方式改变blackviolet我尝试使用

render blur shadow/.append code=
{\colorlet{pstb@shadow@color}{white!\pgfbs@opacity!violet}%
\pgfsetfillcolor{violet}%
},

但这并没有成功,有什么建议吗?

更新

我的意思是,如果有一个像\patchcmdfrom这样的宏etoolbox可以改变 render blur shadow这样的代码,而无需重写代码render blur command

\patchcmd{render blur command}{black}{violet}{<success>}{<failure>}

理想代码

\documentclass[margin=2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadows.blur}

\patchcmd{render blur command}{black}{violet}{<success>}{<failure>}

\begin{document}

\begin{tikzpicture}
\node[fill=white, draw=black, blur shadow,font=\Large] {Node};
\end{tikzpicture}

\end{document} 

答案1

为什么不简单地blackviolet“本地”替换,如下所示:

\documentclass[tikz,border=7mm]{standalone}
\usetikzlibrary{shadows.blur}
\begin{document}
  \tikzset{
    render blur shadow/.prefix code={
      \colorlet{black}{violet}
    }
  }
  \begin{tikzpicture}
    \node[fill=white, draw=black, blur shadow,font=\Large] {Node};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容