21

I am asking for a style (or something similar), let us call it ERASE. The imaginary tool works as a convenient inverse clip or eraser within a scope. The specific way is asked within the comment in the following MWE. The MWE is an abstract form of my use cases (if you do not like the background, think of color wheel graphs from complex analysis to smooth your ruffled feathers).

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{shadings,calc}
\tikzset{nodeStyle/.style={draw,rounded corners,thick,font=\bfseries{}}}
\tikzset{ERASE/.style={}}% just a placeholder

\begin{document}
\begin{tikzpicture}
    \shade[shading=color wheel white center] (0,0) rectangle (10,10);

    \draw[thick] (0,0) -- (10,5);
    \node[nodeStyle,fill=white] at (5,2.5) {filled};
    %This is readable but removes the background. 

    \draw[thick] (0,2) -- (10,7);
    \node[nodeStyle] at (5,4.5) {not filled};

    \begin{scope}
        \draw[line width=1.5ex,color=red!50] (0,6.05) -- (10,6.95);%by @marmot
        \draw[thick] (0,4) -- (10,9);
        \node[nodeStyle,ERASE] at (5,6.5) {ERASE to be implemented};
            % erases everything in this scope "behind" this new object 
            % such that the diagonal line in this node is not visible and 
            % the text is easy to read and the coding is convenient 
    \end{scope}

    \begin{scope}
        % This just illustrates that clip can be used inside a scope
        % thus the desired EREASE instruction might be possible. 
        \clip (1,7) rectangle (8,10);
        \draw[thick] (0,6) -- (8,10);
    \end{scope}

\end{tikzpicture}
\end{document}

enter image description here

This imaginary tool might be unsuited for more complex use cases within several paths involved. Any suggestions on improving the use case are welcome.

2
  • 1
    You can achieve that with the reverseclip trick.
    – user121799
    Sep 1, 2018 at 22:17
  • @marmot Is this a duplicate, do you think? I immediately thought of that kind of solution when I saw this. (Though I thought it was called 'inverse clip' or something like that.)
    – cfr
    Sep 2, 2018 at 3:18

1 Answer 1

23

Here is a version using the reverseclip trick. I am not sure if one can easily implement this as a robust style that can be added to the node since clip does not allow extra options. However, apart from that this does it, I think. EDIT: Simplified the matters by employing use path.

\documentclass{memoir}
\usepackage{fontspec,amsmath,tikz}
\usetikzlibrary{shadings,calc,backgrounds}
\tikzset{nodeStyle/.style={draw,rounded corners,thick}}
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\tikzset{ERASE/.style={save path=\tmprotect
% append after command={\pgfextra{\clip[overlay]
% (\tikzlastnode.south east) rectangle (\tikzlastnode.north west)
% [reverseclip];
% }}
        }}% just a placeholder
\tikzset{reverseclip/.style={insert path={(current bounding box.north
        east) rectangle (current bounding box.south west)}}}

\begin{document}
\begin{tikzpicture}
    \shade[shading=color wheel white center] (0,0) rectangle (10,10);

    \draw[thick] (0,0) -- (10,5);
    \node[nodeStyle,fill=white,font=\bfseries] at (5,2.5) {filled};
    %This is readable but removes the background. 

    \draw[thick] (0,2) -- (10,7);
    \node[nodeStyle,font=\bfseries] at (5,4.5) {not filled};

    \begin{scope}
        \node[nodeStyle,ERASE,font=\bfseries] at (5,6.5) (erase) {ERASE has been implemented};
            % erases everything in this scope "behind" this new object 
            % such that the diagonal line in this node is not visible and 
            % the text is easy to read and the coding is convenient 
        \clip[use path=\tmprotect,reverseclip]; 
        \draw[thick] (0,4) -- (10,9);   
        \draw [ultra thick,red] (0,6.05) -- (10,6.95);
    \end{scope}

    \begin{scope}
        % This just illustrates that clip can be used inside ascope
        % thus the desired EREASE instruction might be possible. 
        \clip (1,7) rectangle (8,10);
        \draw[thick] (0,6) -- (8,10);
    \end{scope}

\end{tikzpicture}
\end{document}

enter image description here

Now also the rounded corners are respected.

enter image description here

1
  • 3
    I don't use tikz but, man, that is a beautiful answer. Nov 2, 2018 at 13:04

You must log in to answer this question.

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