TransWikia.com

TikZ transparency group breaks with overlay

TeX - LaTeX Asked on May 9, 2021

I was trying to implement this solution to draw a transparent arrow using a scope with transparency group. It works fine.

Unfortunately my picture needs to be overlayed on some text. When adding the overlay option to my tikzpicture environment, the scope‘s content simply disappears.

Is there any hope to get that working?

illustration

From left to right: no overlay (works), remember picture with overlay (doesn’t work) on a square, remember picture without overlay (works).

documentclass[margin=.5cm]{standalone}
usepackage{tikz}

begin{document}

begin{tikzpicture}
    draw (-1,-1) rectangle (1,1);
    fill[blue] circle (1);
    begin{scope}[transparency group, opacity=.5]
        fill[red] (.5,.5) circle (.5);
        fill[red] (-.3,-.3) circle (.7);
    end{scope}
end{tikzpicture}

begin{tikzpicture}[remember picture]
    coordinate (z) at (0,0);
    draw (-1,-1) rectangle (1,1);
end{tikzpicture}

begin{tikzpicture}[remember picture, overlay]
    fill[blue] (z) circle (1);
    begin{scope}[transparency group, opacity=.5]
        fill[red] (z) ++(.5,.5) circle (.5);
        fill[red] (z) ++(-.3,-.3) circle (.7);
end{scope}
end{tikzpicture}

begin{tikzpicture}[remember picture]
    fill[blue] (z) circle (1);
    begin{scope}[transparency group, opacity=.5]
        fill[red] (z) ++(.5,.5) circle (.5);
        fill[red] (z) ++(-.3,-.3) circle (.7);
end{scope}
end{tikzpicture}

end{document}

One Answer

The problem is described in the documentation: tikz has to know the size of the picture to be able to produce a correct box, but this size doesn't exist if you use overlay. Section 115.4 Transparency Groups shows a work-around. The trick is to do what you normally don't do: put a tikz picture inside a node:

documentclass[margin=.5cm]{standalone}
usepackage{tikz}

begin{document}

begin{tikzpicture}
    draw (-1,-1) rectangle (1,1);
    fill[blue] circle (1);
    begin{scope}[transparency group, opacity=.5]
        fill[red] (.5,.5) circle (.5);
        fill[red] (-.3,-.3) circle (.7);
    end{scope}
end{tikzpicture}

begin{tikzpicture}[remember picture]
    coordinate (z) at (0,0);
    draw (-1,-1) rectangle (1,1);
end{tikzpicture}

begin{tikzpicture}[remember picture, overlay]
    fill[blue] (z) circle (1);
    node[overlay] at (z)
     { begin{tikzpicture}
       begin{scope}[transparency group, opacity=.5]
        fill[red] (z) ++(.5,.5) circle (.5);
        fill[red] (z) ++(-.3,-.3) circle (.7);
       end{scope}
       end{tikzpicture}};

end{tikzpicture}

begin{tikzpicture}[remember picture]
    fill[blue] (z) circle (1);
    begin{scope}[transparency group, opacity=.5]
        fill[red] (z) ++(.5,.5) circle (.5);
        fill[red] (z) ++(-.3,-.3) circle (.7);
end{scope}
end{tikzpicture}

end{document}

enter image description here

Correct answer by Ulrike Fischer on May 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP