5

Ideally I would imagine that if I overlap the red, yellow, blue three glasses, then I would see more or less a black color in the overlapped region.

However by doing this in LaTeX, it seems I was wrong, the overlapped region is colored by last color I use, regardless the opacity I use. Please see the following MWE and you will get what I mean.

My question is hence, what is the mechanism behind latex rendering overlapped colors? Why there is no mixing effect by using overlap?

MWE

% !TEX TS-program = xelatex 
\documentclass[class=article,border=0pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node [circle, fill=blue, opacity=0.5, minimum size=.4cm] at (0.2cm,0cm) () {};
\node [circle, fill=red, opacity=0.5, minimum size=.4cm] at (0cm,0cm)  () {};
\node [circle, fill=yellow, opacity=0.5, minimum size=.4cm] at (0.1cm,0.2cm)  () {};
\end{tikzpicture}
\end{document}
4

You have to use a blend mode

\documentclass[class=article,border=0pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\begin{scope}[transparency group]
\begin{scope}[blend mode=multiply]
\node [circle, fill=blue, opacity=0.5, minimum size=.4cm] at (0.2cm,0cm) () {};
\node [circle, fill=red, opacity=0.5, minimum size=.4cm] at (0cm,0cm)  () {};
\node [circle, fill=green, opacity=0.5, minimum size=.4cm] at (0.1cm,0.2cm)  () {};
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

For more modes see pgfmanual documentation, page 341, section 23.3.

For xelatex

\documentclass[class=article,border=0pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
%\begin{scope}[transparency group]
\begin{scope}[blend mode=darken]
\node [circle, fill=blue, opacity=0.5, minimum size=.4cm] at (0.2cm,0cm) () {};
\node [circle, fill=red, opacity=0.5, minimum size=.4cm] at (0cm,0cm)  () {};
\node [circle, fill=green, opacity=0.5, minimum size=.4cm] at (0.1cm,0.2cm)  () {};
\end{scope}
%\end{scope}
\end{tikzpicture}
\end{document}
  • I have used green instead of yellow just for demo. – user11232 Apr 14 '15 at 3:31
  • Thanks for your fast response. Sorry I did mean to type green, but I ended with typing yellow. :) – Daniel Apr 14 '15 at 4:50
  • OOPS, it's not working with xelatex. – Daniel Apr 14 '15 at 4:53
  • @Daniel Sorry, there you go. See the edit. Remove transparency group – user11232 Apr 14 '15 at 5:02
  • Using latex+dvips+ps2pdf does not work either, use pdflatex it works. – Daniel Apr 14 '15 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.