Inside a tikzpicture, I am using a white fill for the label of nodes and lines. This generally works well for my needs, but I realized it is not perfect after putting a picture on top of a background image. For my question and MWE here, I am using a simple background color for illustrative purposes. However, I hope that the answer can also be used where there is a background image (e.g. in beamer), hopefully without any modification.
MWE - works with white background only
\documentclass{article}
\usepackage{tikz}%
\begin{document}
\begin{tikzpicture}
\tikzset{mwe/.style={inner sep=1.15ex, text depth=0ex, text height=1ex, text width=0.5em, minimum size=0.5em}}%
\node (A) [mwe,fill=white] at (0,0) {A};%
\node (B) [mwe,fill=white] at (4,0) {B};%
\draw[bend right=45,line width=0.25mm,-] (A) to node [midway,fill=white, text height=1.25ex] {ab} (B);%
\node (C) [mwe,fill=white] at (0,4) {C};%
\node (D) [mwe,fill=white] at (2,-4) {D};%
\draw[bend left=15,line width=0.25mm,-] (C) to node [midway,fill=white, text height=1.25ex] {cd} (D);%
\node (E) [mwe,fill=white] at (-2,2) {E};%
\node (F) [mwe,fill=white] at (4,-2) {F};%
\draw[bend left=15,line width=0.25mm,-] (E) to node [midway,fill=white, text height=1.25ex] {ef} (F);%
\end{tikzpicture}
\end{document}
MWE - different background color
\documentclass{article}
\usepackage{pagecolor}%
\usepackage{tikz}%
\begin{document}
\pagecolor{red!30}
\begin{tikzpicture}
\tikzset{mwe/.style={inner sep=1.15ex, text depth=0ex, text height=1ex, text width=0.5em, minimum size=0.5em}}%
\node (A) [mwe,fill=white] at (0,0) {A};%
\node (B) [mwe,fill=white] at (4,0) {B};%
\draw[bend right=45,line width=0.25mm,-] (A) to node [midway,fill=white, text height=1.25ex] {ab} (B);%
\node (C) [mwe,fill=white] at (0,4) {C};%
\node (D) [mwe,fill=white] at (2,-4) {D};%
\draw[bend left=15,line width=0.25mm,-] (C) to node [midway,fill=white, text height=1.25ex] {cd} (D);%
\node (E) [mwe,fill=white] at (-2,2) {E};%
\node (F) [mwe,fill=white] at (4,-2) {F};%
\draw[bend left=15,line width=0.25mm,-] (E) to node [midway,fill=white, text height=1.25ex] {ef} (F);%
\end{tikzpicture}
\end{document}
Obviously, it would be simple enough to change the fill color to be the same as that of the page background. However, this is not possible to achieve this if you have a background image which has multiple/various colors in it.
Therefore, I am aiming for something like a fill that is effectively opaque to (or blocks out) other elements in the tikzpicture but is actually transparent/invisible to everything outside of the tikzpicture. It may be better to say that the fill is completely transparent...however it maintains the effect of erasing the lines, nodes, and any other elements in the tikzpicture behind/underneath.
Is this possible with tikz? Perhaps not possible using fill per se, but through any mechanism(s)?
edit: I wrote "translucent" originally...I meant "transparent". Sorry for the confusion!
Bonus: If the labels could also make foreground lines "disappear", that would be good. Except that labels should not be able to make other labels disappear. For example, in the first MWE, cd is underneath the ef line, so it would be nice to have that section of the ef line erased. The same is true for the ab label underneath the cd line. This would be a bonus, but is not necessary for an answer.
The intended image would look something like this, where any background/color would appear behind/around the labels:




c' andab' would generally be within a bend, unlike my example above. I'll work on an edit with that incorporated to avoid confusion. – whatisit Aug 02 '16 at 08:54knockoutgroup? But this is very PDF viewer dependent. (I can't test it for just this reason, in fact.) (Adobe Reader crashed repeatedly and I'm not sure it works properly in my version anyway. I don't know that knockout crashed it. It would probably have crashed anyhow. It is crap, basically.) – cfr Aug 03 '16 at 00:57scopeenvironment andtransparency groupalong withknockoutand can't really do much remotely productive. Perhaps someone more familiar could provide an example withknockout? Also, I found almost what I want with\draw[bend left=65,-,decoration={markings,mark connection node=ce,mark=at position .5 with {\node [text height=1.25ex,postaction={decorate}] (ce) {ce};}}] decorate{(E) to (C)};. If you take out thebend left=65, it's actually perfect. I can't find any way to incorporate a bend into this, however. – whatisit Aug 03 '16 at 10:56\drawcommand requires\usetikzlibrary{decorations.markings}, by the way). I tried playing around withpreactionandpostactionalso, but this either does a bend (but puts the text onto the line, like normal) or gets the straight (rather than bent) lines. Seems I can't have my cake and eat it too! – whatisit Aug 03 '16 at 10:59