0

I can clip everything that is outside of a box

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[]
\clip (-1, 0) rectangle (1, 1);
\draw (0, 0) circle (2 and .5);
\end{tikzpicture}
\end{document}

But how can I go about clipping things that are inside a rectangle, and drawing only things that are outside of the rectangle ?

I can clip with a complicated polygon

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[]
\clip (-1, 0) -- (1, 0) --  (1, 1) -- (3, 1) -- (3, -1) -- (-3, -1) -- (-3, 1) -- (-1, 1) -- (-1, 0) -- cycle;
\draw (0, 0) circle (2 and .5);
\end{tikzpicture}
\end{document}

But is there a simpler way to do this?

  • 1
    In other words, do you want a white filled rectangle withou stroke over any other draws? – Sigur Apr 16 at 16:01
2

There are several posts on even odd clip and reversclip` that can be used here.

\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 
\tikzset{even odd clip/.code={\pgfseteorule},
reverseclip/.style={overlay,insert path={(-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)}}}

\begin{document}
\noindent
\begin{tikzpicture}[]
\draw (-1, 0) rectangle (1, 1);
\draw (0, 0) circle (2 and .5);
\end{tikzpicture}

\noindent
\begin{tikzpicture}[]
\path[save path=\pathA] (0, 0) circle (2 and .5);
\clip[overlay,even odd clip,reverseclip] (-1, 0) rectangle (1, 1) ; 
\draw[use path=\pathA] (0, 0) circle (2 and .5);
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.