我不想为绘制框中的某些文本定义特定颜色,而是希望将文本从框中剪掉,以便可以看到纸张颜色。这是 MWE:
\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usepackage{geometry}
\usetikzlibrary{positioning,calc,intersections}
\geometry{papersize={70mm, 20mm}}
\newcommand\placeTextBox[7]{
\begin{tikzpicture}[remember picture,overlay]
\fontsize{#5}{#5}\selectfont
\filldraw [fill=#7, draw=#7, line width=0.25mm, rounded corners=0.25mm]
($(current page.south west)+(#1,#2)-(#3/2,#4/2)$) rectangle
($(current page.south west)+(#1,#2)+(#3/2,#4/2)$)
node[pos=0.5, text depth=0pt, text=white] {#6};
\end{tikzpicture}
}
\tikzstyle{reverseclip}=[insert path={(current page.north east) --
(current page.south east) --
(current page.south west) --
(current page.north west) --
cycle}
]
\begin{document}
\placeTextBox{35mm}{10mm}{30mm}{3.1mm}{3.0mm}{\textbf{Transparent text}}{black}
\end{document}
这给出了以下结果:
但是,除了在节点中使用“text=white”作为文本外,我还需要做什么才能将文本从黑框中剪切出来,从而显示出红色的纸张颜色?
答案1
您可以使用knockout
组,但许多查看器不支持。您也可以tikzfadingfrompicture
像这样使用
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{fadings, patterns}
\begin{tikzfadingfrompicture}[name=myfading]
\node[fill=transparent!0] {\textbf Transparent text};
\end{tikzfadingfrompicture}
\begin{document}
\begin{tikzpicture}
\pattern [pattern=checkerboard,pattern color=black!30] (-2,-1) rectangle (2,1);
\fill[red, path fading=myfading, fit fading=false] (-2,-1) rectangle (2,1);
\end{tikzpicture}
\end{document}