2

I've searched a bit and tried in different ways but I don't manage to get the area of the inside circle unfilled, or, alternatively, to be able to fill only the area between the two circles.

Here is a MWE:

\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[step=1cm, gray, very thin] (-3.5,-2.5) grid (3.5,2.5);
\draw (0,0) circle (2cm);
\path[fill=gray, opacity=0.2] (0,0) circle (2cm);
\draw[dashed] (0,0) circle (1cm);
\end{tikzpicture}

\end{document}

And here is what it plots: enter image description here

Edit:

I've found an answer here: Filling the area between two circles still want to know if it is possible to unfill a previously filled area though.

Thank you for your time.

  • 3
    The short answer is no, you cannot "unfill" an area. You can fill on top of it, but hidden background objects will stay hidden. You can, however, not fill part of a filled area in the first place. – John Kormylo Oct 6 '18 at 12:42
  • If your question is how not to fill the circle in the middle, then you may just be looking for even odd rule: \path[fill=gray, opacity=0.2,even odd rule] (0,0) circle (2cm) circle (1cm); – user121799 Oct 6 '18 at 13:02
4

I think you are only looking for even odd rule.

\documentclass[12pt]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[step=1cm, gray, very thin] (-3.5,-2.5) grid (3.5,2.5);
\draw (0,0) circle (2cm);
\path[fill=gray, opacity=0.2,even odd rule] (0,0) circle (2cm) circle (1cm);
\draw[dashed] (0,0) circle (1cm);
\end{tikzpicture}

\end{document}

enter image description here

The closest thing to "unfilling" that comes to my mind is do all the fills on the background layer. Then the effect may (or may not, depending on whom you ask;-) be described as "unfilling".

\documentclass[margin=3.14mm, tikz]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}
\foreach \X in {0,1}
{\begin{tikzpicture}
\draw[step=1cm, gray, very thin] (-3.5,-2.5) grid (3.5,2.5);
\draw (0,0) circle (2cm);
\ifnum\X=0
\node[anchor=south,font=\sffamily] at (0,2) {fill};
\else
\node[anchor=south,font=\sffamily] at (0,2) {``unfill''};
\fi
\begin{scope}[on background layer]
\path[fill=gray, opacity=0.2] (0,0) circle (2cm) circle (1cm);
\ifnum\X=0
\draw[dashed] (0,0) circle (1cm);
\else
\draw[dashed,fill=white] (0,0) circle (1cm);
\fi
\end{scope}
\end{tikzpicture}}
\end{document}

enter image description here

  • Thank you, I've previously edited the question to clarify that I'm looking for a method different from the even or odd one but as John Kormylo said in his comment maybe it is impossible to do – Edoardo Serra Oct 6 '18 at 17:38
  • 1
    @EdoardoSerra I added a second possibility which may come close to "unfilling". – user121799 Oct 6 '18 at 17:50

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.