1

I wish build up a tikz picture from layers. Is there a way to draw/fill one of the layer with "eraser" (not transparency)? Somehow:

enter image description here

I have no idea therefore neither MWE :-/

(I know, that there is an easier way to do the example document above, but that is only an example.)

4
  • 4
    mwe is usually added to save us from the annoyance of writing those rectangle and color parts.
    – percusse
    Dec 28, 2016 at 16:01
  • your question is not clear. see, if the following MWE gives what you expect: \documentclass[tikz, margin=3mm]{standalone} \begin{document} \begin{tikzpicture}[ box/.style args = {#1/#2}{minimum size=#1, fill=#2, font=\Large\sffamily\bfseries} ] \node[box=44mm/green,draw] {Text}; \node[box=33mm/red] {}; \node[box=22mm/white,draw] {}; \node[box=11mm/blue] {}; \end{tikzpicture} \end{document}
    – Zarko
    Dec 28, 2016 at 17:29
  • What you are asking cannot be constructed by piling layers on top of each other; in effect, you want your eraser layer to cut into the layers beneath it. AFAIK that is impossible. This question discusses a possible work-around: tex.stackexchange.com/questions/336502/… Dec 28, 2016 at 19:54
  • 2
    Keyword: knockout group and inverse clipping
    – Symbol 1
    Dec 29, 2016 at 0:50

1 Answer 1

3

Instead of erasing, you could simply not draw the filling in the first place:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\fill[green] (0,0) rectangle (1,1);
\draw[red, line width=3pt] (0.2,0.2) rectangle (0.8,0.8);
\fill[blue] (0.4,0.4) rectangle (0.6,0.6);
\end{tikzpicture}

\end{document}

enter image description here

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