I noticed first that yellow!50!green did not produce the same color as green!50!yellow. Then I tried more systematically:

\foreach\y in {0,10,...,100} {
\fill[green!\y!yellow] (.1*\y,0) rectangle ++(1,1);
\fill[yellow!\y!green] (.1*\y,2) rectangle ++(1,1);

This is what I get: mix green and yellow

What exactly is going on there?

  • 7
    Load the package xcolor before tikz with an option other than natural, say rgb or cmyk depending on your document. Then the colors will mix properly. (Green comes from rgb, yellow from cmyk.) Commented Jul 8, 2023 at 2:01
  • @Qrrbrbirlbel In light of the existing answer, could you elaborate a bit more?
    – Teepeemm
    Commented Jul 8, 2023 at 15:27
  • @Teepeemm I'm working on something. I'm not an expert on colors and color models and color conversion but I have solutions. (The easiest one would be to chose one or the other …) Commented Jul 8, 2023 at 17:48
  • Or not. Muzimuzhi has basically posted what I had worked on. Let me leave some links to related Q&A: 1, 2 Commented Jul 8, 2023 at 21:27
  • You mix green!y with yellow, and yellow!y with green. It‘s not symmetrical by syntax.
    – MS-SPO
    Commented Jul 9, 2023 at 10:37

1 Answer 1

  1. xcolor uses color model natural by default.
    (See xcolor package doc, Table 1: "Package options".)
  2. In natural color model, green is in rgb model and yellor is in cmyk model.
    (Can only be checked clearly from source code (1 and 2), but the Figure 4: "Target color model" in package doc tells the difference a bit.)
  3. In a color mix expression like <name1>!<pct>!<name2> (<pct> is short for percent), if <name1> and <name2> are in different color models, in normal case when 0 < <pct> < 100 the resulting color has the same model with <name1>.
    (See xcolor package doc, sec. 2.3.2 "Meaning of standard color expressions", the note paragraph after numbered list.)
  4. Specifically, if <pct> is 0, <name2> is returned, without model transformation. In this case, the resulting color has the same model with <name2>, not <name1>.

To set or change current color model, one of the following ways can be used:

  • Use \PassOptionsToPackage{<model>}{xcolor} before xcolor is loaded.
  • Use model name as package option, for example \usepackage[rgb]{xcolor}.
  • Use \selectcolormodel{<model>} after xcolor is loaded.

  \makebox[4cm][l]{\detokenize{"#1"}} ->

  \noindent Color Model: \texttt{#1}\\
    \foreach \y in {0,10,...,100} {
      \fill[green!\y!yellow] (.1*\y,0) rectangle ++(1,1);
      \fill[yellow!\y!green] (.1*\y,1.1) rectangle ++(1,1);



Color Model: \texttt{natural}




\testColorMixing{natural} % default

enter image description here

  • 1
    Great insight. +1
    – MS-SPO
    Commented Jul 9, 2023 at 10:51

You must log in to answer this question.

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