1
\documentclass[crop]{minimal}

\usepackage{tikz}

\begin{document}
\tikz
{
    \draw [fill=blue] (0, 0) rectangle (2, 2);
    \draw [stroke=black, circle, fill=transparent]  (1, 1) circle (1);
}
\end{document}

produces

a black circle within a blue square

while I'd expect it to produce

a white circle within a blue square

What I'd like to actually do is have a shape which erases the stuff behind it. Currently I fill it with a background color, but I have to change that twice to accommodate a black and white background. The questions relating to that topic usually have answers which works for selected PDF viewers, but I'm using dvisvgm to convert into svg which isn't able to do that.

fill=none just makes the circle fill nothing, and blue remains.

1
  • 2
    You cannot "erase" something that has already been drawn. Use the even-odd rule fill instead. Jan 14, 2022 at 12:13

1 Answer 1

1

It is not possible to erase something that has already been drawn. Either you paint over it using the background color (white in this case) or you use the even odd rule.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikz
  \draw [fill=blue, even odd rule]
    (0, 0) rectangle (2, 2)
    (1, 1) circle (1);
\end{document}

enter image description here

2
  • Understood, thanks for the answer. Now I'm curious about what the color transparent actually means then, if not erase? Why does it show up as black? Jan 14, 2022 at 13:18
  • @DesmondWillowbrook Short answer: transparent is only meaningful for shadings. For a long answer please read Chapter 23 Transparency in the PGF manual. Jan 14, 2022 at 13:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .