TiKZ 复制阴影带有水印问题

TiKZ 复制阴影带有水印问题

在 MWE 中,我们可以看到带有文本的阴影节点。如果我们不添加水印,则第一个 TiKZ 节点上的结果与预期一致,但如果添加水印,选项fill=write所需的选项copy shadow会用白色填充节点,从而去除水印区域,因此我添加了text opacityfill opacity选项(显示在第二个 TiKZ 图片上),但在这种情况下,阴影被删除了,这是 TiKZ 上阴影的工作方式所导致的,这是可以预见的。

我怎样才能实现第一个节点的外观,带有阴影和透明度,以不与水印重叠?

MWE(需要 mwe 包中的 example-grid-100x100bp.jpg):

\documentclass{article}
\usepackage{tikz}\usetikzlibrary{shadows}
\usepackage{graphicx}
\usepackage[absolute]{textpos}
\parindent0pt
\begin{document}
 \begin{textblock*}{\textwidth}(0pt,0pt)
  \includegraphics[scale=2]{example-grid-100x100bp.jpg}
 \end{textblock*}
 \begin{tikzpicture}
  \node[draw=black, fill=white, line width=1pt, rounded corners=3pt, copy shadow={top color=black, bottom color=black, shadow xshift=2pt, shadow yshift=-2pt}]{test1};
 \end{tikzpicture}
 \begin{tikzpicture}
  \node[draw=black, fill=white, fill opacity=0, text opacity=1, line width=1pt, rounded corners=3pt, copy shadow={top color=black, bottom color=black, shadow xshift=2pt, shadow yshift=-2pt}]{test2};
 \end{tikzpicture}
\end{document}

答案1

我希望没有看错问题。您可以使用反向剪辑。但除非有人想太过黑客化,否则这可能意味着必须绘制两次节点。因此这里的步骤是

  1. 绘制节点没有阴影并保存节点边界路径。
  2. 保护节点边界路径。
  3. 绘制节点影和fill opacity=1

人们可以尝试破解影子机制,但不确定这是否值得付出努力。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows}
% based on 
% https://tex.stackexchange.com/a/38995/121799 
% https://tex.stackexchange.com/a/76216 
% https://tex.stackexchange.com/a/59168/194703 
% https://tex.stackexchange.com/q/448920/194703  
\makeatletter 
\tikzset{ 
reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}} 
} 
\tikzset{even odd clip/.code={\pgfseteorule}, 
protect/.code={ 
\clip[overlay,even odd clip,reuse path=#1] 
(-6383.99999pt,-6383.99999pt) rectangle (6383.99999pt,6383.99999pt); 
}} 
\usepackage[absolute]{textpos}
\parindent0pt
\begin{document}
 \begin{textblock*}{\textwidth}(0pt,0pt)
  \includegraphics[scale=2]{example-grid-100x100bp.jpg}
 \end{textblock*}
 \begin{tikzpicture}
  \node[draw=black, fill=white, line width=1pt, rounded corners=3pt, copy shadow={top color=black, bottom color=black, shadow xshift=2pt, shadow yshift=-2pt}]{test1};
 \end{tikzpicture}
 \begin{tikzpicture}
  \node[draw=black, fill=white, fill opacity=0, text opacity=1, line width=1pt,
    rounded corners=3pt,save path=\tmprotect,
    %copy shadow={top color=black, bottom color=black, shadow xshift=2pt, shadow yshift=-2pt}
    ]{test2};
  \tikzset{protect=\tmprotect}  
  \node[draw=black, fill=white, text opacity=1, line width=1pt, rounded corners=3pt, copy shadow={top color=black, bottom color=black, shadow xshift=2pt, shadow yshift=-2pt}]{test2};  
 \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容