1

I wonder if there is a conveniant way to skip a path/shape. For example, I can use \draw (0, 0) -- [clip path={...}] (2, 3); or \draw (0, 0) -- [clip path name=<path name>] (2, 3); or \draw (0, 0) -- [clip node=<nodename>] (2, 3); to skip the given path/node.

I know some code to do this, but they cost several lines:

Inverse clip

\documentclass[tikz, border=1cm]{standalone}

\tikzset{ revclip/.style={ insert path={ (current page.north east) -- (current page.south east) -- (current page.south west) -- (current page.north west) -- (current page.north east) }, }, }

\begin{document} \begin{tikzpicture} \draw (1, 1) circle (1cm); \draw (0.6, 1) circle (0.5cm); \path [clip, overlay] (1, 1) circle (1cm) [revclip]; \draw (0, 0) -- (2, 3); \end{tikzpicture} \end{document}

Background layer

\documentclass[tikz, border=1cm]{standalone}
\pgfdeclarelayer{back}
\pgfsetlayers{back, main}

\begin{document} \begin{tikzpicture} \draw (1, 1) circle (1cm); \draw (0.6, 1) circle (0.5cm); \begin{pgfonlayer}{back} \draw (0, 0) -- (2, 3); \fill[white, behind path] (1, 1) circle (1cm); \end{pgfonlayer} \end{tikzpicture} \end{document}

enter image description here

ZhiyuanLck
  • 4,516
  • \begin{tikzpicture} \draw[ (0, 0) -- (2, 3); \fill[white, draw=black] (1, 1) circle (1cm); \end{tikzpicture} do same thing. No backgrounds library needed. –  Jun 28 '20 at 19:40
  • @ferahfeza I have changed my example to show the necessity of background layer. – ZhiyuanLck Jun 29 '20 at 02:13
  • Sorry I guess I could not fully understand your question. But this code also give same output: \draw (0, 0) -- (2, 3); \fill[white,draw=black] (1, 1) circle (1cm); \draw (0.6, 1) circle (0.5cm); –  Jun 29 '20 at 07:04
  • @ferahfeza yes, there are many ways, I am just assuming a situation that I am drawing a path with another path/shape on the way, and it cost a lot or is impossible to adjust the order of drawing to hide part of current path behind. – ZhiyuanLck Jun 29 '20 at 07:48

0 Answers0