4

For pstricks the package pst-rputover (new on ctan since 2017-03-28) has been created to solve following problem

In brief, I'm looking for a version of \rput* that blocks out lines but not fill colors.

raised here: Is there a variant of \rput* in PSTricks that preserves background fill colors?

I am interested in a solution for tikz. I have recreated the minimal example with tikz:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \fill[blue!40] (0,0) rectangle (2,2);
  \fill[red] plot [smooth] coordinates {(0,2)(1,1)(2,2)} -- cycle;
  \draw(1,0)--(1,2);
  \node at (1,1) {\Large\sf label};
\end{tikzpicture}
\end{document}

enter image description here

The expected output should be

enter image description here

I am evaluating following options in tikz:

  • draw/fill/text opacity
  • transparency groups
  • \begin{scope}
  • \begin{pgfonlayer}

Note the knockout feature is not supported by all PDF Viewer. I can confirm that it does not work in Skim and Preview on macOS.

However, I have not figured out yet how to solve this.

UPDATE I want to add parts of the picture I am working on to clarify that lines might cross several nodes which is a priori not clear:

enter image description here enter image description here

pst-rputover doc details

The style combines two ideas. The first idea, suggested by the StackExchange user Werner on this page, is to use \psDefBoxNodes in pst-node.sty to get the coordinates of the corners of the box occupied by each label. The second idea is to use these coordinates and \psclip to remove the parts of the objects in the argument of \coverable that overlap with the labels. The only subtlety in implementing this second idea is that we want to do a ‘reverse clip’: we want to keep the areas outside the labels, not the ones inside.

Related questions

0

3 Answers 3

4

Just for completeness: this is a version which also takes into account rounded corners or, more generally, arbitrary node shapes. And it spares you from typing a lot of coordinates.

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\makeatletter % https://tex.stackexchange.com/a/38995/121799
\tikzset{
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\tikzset{remember path/.style={save path=\tmprotect}}
% https://tex.stackexchange.com/a/12033/121799
\tikzset{reverseclip/.style={insert path={(current bounding box.north
        east) rectangle (current bounding box.south west)}}}

\begin{document}
\begin{tikzpicture}
  \fill[blue!40] (0,0) rectangle (2,2);
  \fill[red] plot [smooth] coordinates {(0,2)(1,1)(2,2)} -- cycle;
  \node[remember path,font=\Large\sf] at (1,1) {label};
  \clip[use path=\tmprotect,reverseclip];
  \draw(1,0)--(1,2);
\end{tikzpicture}

\begin{tikzpicture}
  \fill[blue!40] (-1,0) rectangle (3,4);
  \fill[red] plot [smooth] coordinates {(-1,4)(0,2)(1,1)(2,2)(3,4)} -- cycle;
  \node[remember path,font=\Large\sf,rounded corners] at (1,1) {label};
  \clip[use path=\tmprotect,reverseclip];
  \node[remember path,font=\Large\sf,shape=diamond] at (2,2) {label 3};
  \clip[use path=\tmprotect,reverseclip];
  \node[remember path,font=\Large\sf,shape=ellipse] at (0,2) {label 2};
  \clip[use path=\tmprotect,reverseclip];
  \fill[gray,opacity=0.2] (-1,0) rectangle (3,4);
  \draw [blue,thick] (-1,4) -- (1,0) -- (3,4);
\end{tikzpicture}
\end{document}

enter image description here

2
  • 2
    +1: Great! Is \tmprotect already predefined? Nov 1, 2018 at 15:28
  • 1
    @Dr.ManuelKuehner No, only here.
    – user121799
    Nov 1, 2018 at 15:39
6

You can clip against the labels:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}

  \fill[color=blue!40] (0,0) rectangle (2,2);
  \fill[red] plot [smooth] coordinates {(0,2)(1,1)(2,2)} -- cycle;

  \node at (1,1) (mynodeA){\Large\sffamily label};
  \node at (0.5,1.5) (mynodeB){\sffamily label};

  \begin{scope}
  \foreach \n in {mynodeA, mynodeB}{
    \path [clip] 
          (\n.north east) -- 
          (\n.south east) --
          (\n.south west) -- 
          (\n.north west) -- cycle
          (current bounding box.south east) --
          (current bounding box.north east) --
          (current bounding box.north west) --
          (current bounding box.south west) -- cycle;
  }

  \draw(1,0)--(1,2);
  \draw(0.5,0)--(0.5,2);
  \draw(0,1.8)--(2,0.5);
  \end{scope}

\end{tikzpicture}
\end{document}

enter image description here

2
  • Thank you very much. This looks like what I want. The actual picture contains 55 nodes and 120 edges which have to be clipped. I think I will use a foreach loop to to define the clippath for every node to make the code more manageable.
    – Hotschke
    Nov 1, 2018 at 12:30
  • Your rputover code is actually doing something similar. Nov 1, 2018 at 12:53
2

with drawing line in two parts?

enter image description here

\documentclass[tikz, margin=3.141592]{standalone}
\begin{document}
\begin{tikzpicture}
  \fill[blue!40] (0,0) rectangle (2,2);
  \fill[red] plot [smooth] coordinates {(0,2)(1,1)(2,2)} -- cycle;
  \node at (1,1)  (label) {\Large\sf label};
  \draw (1,0) -- (label) (label) -- (1,2);
\end{tikzpicture}
\end{document}
4
  • Thanks for the answer. But that is how I created the expected output. The actual document is complicated and doing this manually is not feasible. I really look for an \rputover equivalent.
    – Hotschke
    Nov 1, 2018 at 12:24
  • margin=3.14 - - > :) Nov 1, 2018 at 15:29
  • 1
    @Dr.ManuelKuehner, just for fun ... (my country is so tiny that you will miss it if we haven't have so accurate defined borders ;-) )
    – Zarko
    Nov 1, 2018 at 20:28
  • @Zarko I will read your answers even more carefully in the future. :) Nov 1, 2018 at 21:28

You must log in to answer this question.

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