I have always wondered whether it was possible to define some sort of "relative" transparency in TikZ. What do I mean?
Sometimes, you want a node to be filled in order for its content to be readable among lines and shapes. Now, imagine you have a TikZ picture on some shaded background. It would be great if one could specify that the node should be opaque with respect to the rest of the picture (or the scope), but stay transparent with respect to the background defined outside.
\documentclass{article}
\usepackage{framed,xcolor,tikz}
\definecolor{shadecolor}{gray}{.85}
\begin{document}
\begin{shaded}
\begin{tikzpicture}
\draw (0,0) --node[fill=shadecolor] {a} (5,0);
\end{tikzpicture}
\end{shaded}
\end{document}
In the above situation, it is possible to use shadecolor
, because this is how the shaded
environment works. I would like to know whether a more general solution exists, e.g. one that works in situations where you cannot find out the background color of the surrounding environment.
Updated information
I will try to state things a bit clearer. I often use TikZ for geometric figures and/or plots. Then, sometimes you have lines running through a coordinate label. In most cases, it is enough to slightly change the figure, e.g. by moving the label to a different anchor or even adapt some angle and thus have the line just miss the label.
However, in some cases, there is no other way than to put the label in a filled node with an inner sep of 1 or 2 points, so that it stands out among all other stuff. The main problem is that I have to use the background color to fill my node, normally this is white, but sometimes it might be some gray color.
The example I included is very easy, just to illustrate the problem. In this simple case, I could, of course, just draw the line in two pieces. In a normal use case, this is not possible.
So another way of saying it: I would love to draw the figure just as if there was a white background, using fill=white
for such nodes. And then, after all is finished, I could say that all white stuff becomes transparent, so that the gray (or whatever) background shines through.
Using percusse's solution with transparency group
s, it is not possible to achieve what I am looking for. The whole scope becomes partially transparent, so the line is not black anymore and the background is still lightened up. I would want the line to stay completely black and the node fill to be completely invisible.