我怎样才能绘制像这样带有各种孔的 tikzpicture?

我怎样才能绘制像这样带有各种孔的 tikzpicture?

我如何绘制像下面这样的 tikzpicture?我无法绘制矩形(显示器)和圆角矩形(耳机扬声器)孔。我的想法是让它们完全透明,这样背景颜色就可以透过它们看到。

enter image description here

这是我的代码:

\documentclass{article}
\usepackage{pgf,tikz}
\tikzset{mystyle/.style={shape=rectangle,rounded corners,fill=white}}
\begin{document}
 \begin{tikzpicture}[scale=1]
 \fill[blue](-5,-5)rectangle(5,5); % background
 \filldraw[fill=white,rounded corners=0.5cm](-2,-4)rectangle(2,4) % phone case
    [sharp corners](-1.75,-3)rectangle(1.75,3) % display
    (0,-3.5)circle(0.25cm) % button
   [rounded corners=0.125cm](-0.5,3.325)rectangle(0.5,3.625); %earpiece speaker
 % Picture labels
 \draw[ultra thick](0,0)--(-30:4)node[mystyle]{Not blue}[ultra thick]--(0,3.5);
 \draw[ultra thick](0,-3.5)--(210:4)node[mystyle]{Blue};
 \end{tikzpicture}
\end{document}

结果如下:

enter image description here

答案1

使用even odd rule

\documentclass{article}
\usepackage{pgf,tikz}
\tikzset{mystyle/.style={shape=rectangle,rounded corners,fill=white}}
\begin{document}
 \begin{tikzpicture}[scale=1]
 \fill[blue](-5,-5)rectangle(5,5); % background
 \filldraw[fill=white,rounded corners=0.5cm,even odd rule](-2,-4)rectangle(2,4) % phone case
    [sharp corners](-1.75,-3)rectangle(1.75,3) % display
    (0,-3.5)circle(0.25cm) % button
   [rounded corners=0.125cm](-0.5,3.325)rectangle(0.5,3.625); %earpiece speaker
 % Picture labels
 \draw[ultra thick](0,0)--(-30:4)node[mystyle]{Now blue}[ultra thick]--(0,3.5);
 \draw[ultra thick](0,-3.5)--(210:4)node[mystyle]{Blue};
 \end{tikzpicture}
\end{document}

enter image description here

相关内容