我尝试用半透明矩形覆盖图片,然后剪切出一些形状(矩形和圆形),以便图像在这些形状中清晰可见,然后使用类似 tikz\pin
命令的命令指向剪切部分。我的问题是,我能找到的剪切示例只有\fill
,然后简单地堆叠剪切块形状。有没有办法直接从节点创建这些剪切块,以便以后可以引用这些节点?目前,我只是稍后定义具有相同坐标的另一个节点来引用它,但如果可以直接使用节点进行剪切,那就干净多了。MWE(无节点,来自 Alex Recuenco 在此问题中的回答中的示例:如何创建带有透明孔的矩形):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\section{Non Zero Rule}
\begin{tikzpicture}
\draw[black, fill = black, fill opacity = 0.5, semithick]
(0,0) rectangle (5,5) (2.5,2.5) circle (0.5);
\end{tikzpicture}
\section{Even Odd Rule}
\begin{tikzpicture}
% \node (image) {\includegraphics{somepic_with_cool_features}}
\draw[black, fill = black, fill opacity = 0.5, semithick, even odd rule]
(0,0) rectangle (5,5) (2.5,2.5) circle (0.5);
\end{tikzpicture}
\end{document}
澄清一下:我的梦想是拥有类似的东西
% \node (image) {\includegraphics{somepic_with_cool_features}}
\draw[black, fill = black, fill opacity = 0.5, semithick, even odd rule]
(0,0) rectangle (5,5) {%
\node[pin={[red]60:Cool feature one!}] (circ1) (2.5,2.5) circle (0.5);
\node[pin={[red]60:Wow another one!}] (circ2) (4,4) circle (0.5);
\node[pin={[red]60:A whole bunch!}] (rect1) (5,6) rectangle (7,9);%
}
答案1
您可以使用节点边界路径进行反向剪辑,以防止其被过度绘制。这非常类似于橡皮擦工具。
\documentclass{article}
\usepackage{tikz}
% 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}}
}
\makeatother
\tikzset{even odd clip/.code={\pgfseteorule},
protect/.code={
\clip[overlay,even odd clip,reuse path=#1]
(-5383.99999pt,-5383.99999pt) rectangle (5383.99999pt,5383.99999pt);
}}
\begin{document}
\section{Protect}
\begin{tikzpicture}
\path (2.5,2.5) node[draw,circle,save path=\pathA,minimum size=1cm](c){};
\tikzset{protect=\pathA}
\draw[overlay=false,black, fill = black, fill opacity = 0.5, semithick]
(0,0) rectangle (5,5);
\draw[stealth-] (c) -- ++ (60:1) node[above]{here};
\end{tikzpicture}
\end{document}