正确使用 TikZ 淡入淡出从圆角框中剪切文本

正确使用 TikZ 淡入淡出从圆角框中剪切文本

跟进帖子中,我试图构建一个如下所示的插图:

在此处输入图片描述

重要的是透明文本确实是透明的,而不是白色。

当我编译以下 MWE 时

\documentclass{article}
\pagestyle{empty}

\usepackage{tikz}
\usepackage{geometry}
\usepackage{anyfontsize}
\usepackage{xcolor}

\usetikzlibrary{positioning,calc,intersections,fadings}

\geometry{papersize={50mm, 30mm}}

\newcommand\lw{0.25mm}   % Line widths
\newcommand\tbh{3.75mm}  % Text box height
\newcommand\rcr{0.4mm}   % Rounded corners radius

\newcommand\PlaceTextRRA[6]{
\begin{tikzfadingfrompicture}[name=myFading]
\fontsize{#5}{#5}\selectfont
\node[text=transparent!0] {\textbf{Transparent text}};
\end{tikzfadingfrompicture}
\begin{tikzpicture}[remember picture, overlay]
%\fontsize{#5}{#5}\selectfont
\draw [rounded corners=\rcr, line width=\lw, draw=black] 
    ($(current page.south west)+(#1,#2)$) --
    ($(current page.south west)+(#1,#4)$) --
    ($(current page.south west)+(#3,#4)$) --
    ($(current page.south west)+(#3,#2)$) -- cycle  ;
\draw [line width=\lw, draw=black]
    ($(current page.south west)+(#1,#2)+(0,\tbh)$) --
    ($(current page.south west)+(#3,#2)+(0,\tbh)$);
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay]
\filldraw[fill=black, draw=black, rounded corners=\rcr, line width=\lw, path fading=myFading]
    ($(current page.south west)+(#1,#2)$) rectangle ($(current page.south west)+(#3,#2)+(0,\tbh)$);
\end{tikzpicture}
}
   
\begin{document}
\PlaceTextRRA{5mm}{5mm}{45mm}{25mm}{3.5mm}{\textbf{Transparent Text}}
\end{document}

我得到以下结果:

在此处输入图片描述

如果我将其添加fit fading=false\filldrawMWE 的末尾,我会得到以下结果:

在此处输入图片描述

我为此绞尽脑汁好几个小时,但就是无法解决。谁能给我指点迷津?

答案1

我认为这不是答案,但可能是不错的选择:

在此处输入图片描述

\documentclass[a4paper,14pt]{extreport}
\usepackage[left=1.5cm,right=1.5cm,
top=1.5cm,bottom=2cm,bindingoffset=0cm]{geometry}


\usepackage{tikz}

\usepackage[most]{tcolorbox}
\tcbuselibrary{skins}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{decorations.pathmorphing}

\tcbset{%
    myboxmainstyle/.style={%
      enhanced,
      segmentation style={solid,line width=1pt,decorate,decoration={zigzag}},
      center title,
      halign=flush center,
      boxrule=1pt,
      arc is angular, arc=1mm,
    }
}


\newtcolorbox{mybox}[2][]{
  enhanced,
  sharp corners=south,
  myboxmainstyle,
  attach boxed title to bottom center={yshift=0.5mm},
  minipage boxed title*,
  boxed title style={enhanced,
    size=normal,
    top=0pt,
    bottom=0pt,
    center title,
    sharp corners=north,
    boxrule=1pt,
    arc is angular, arc=3pt},
  title={{\centering #2}},#1
}



\begin{document}


    \begin{mybox}[]{Test}
        bla bla
    \end{mybox}
    \begin{mybox}[colback={yellow},coltitle=black,colbacktitle=red]{Another Test}
        bla bla
    \end{mybox}

\end{document}

相关内容