Why does xcolor lighten a color when mixed
The xcolor
package defines blue
as a RGB color and cyan
as a CMY color.
To make a mix, xcolor
uses the color model of the first color and, if necessary, converts the second color.
To convert the CMY cyan
to RGB cyan
, you may add \colorlet{cyan}[rgb]{cyan}
in your preamble.
\documentclass[tikz]{standalone}
\usepackage{tikz}
\colorlet{cyan}[rgb]{cyan}
\begin{document}
\begin{tikzpicture}
\draw[cyan,fill=cyan] (0,0) rectangle (1,1);
\draw[blue!0.5!cyan,fill=blue!0.5!cyan] (1,0) rectangle (2,1);
\end{tikzpicture}
\end{document}
Extract from xcolor
manual (section 2.3.2 "Meaning of standard color expressions", p. 15, v2.11):
In general, the second color is transformed into the model of the first color then the mix is calculated within that model. Thus,
name1!<percent>!name2
andname2!<100-percent>!name1
which should be equivalent theoretically, will not necessarily yield identical visual results.
Here is an example with three rows: default models, pure rgb model and pure cmy model.
\documentclass[tikz,margin=1mm]{standalone}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{positioning}
\colorlet{cmycyan}{cyan}
\colorlet{rgbcyan}[rgb]{cyan}
\colorlet{cmyblue}[cmy]{blue}
\colorlet{rgbblue}{blue}
\begin{document}
\begin{tikzpicture}
\tikzset{
block/.style 2 args={
draw,right=-.5\pgflinewidth of a,
fill=#1,text=#2,
text height=.8em,text depth=.2em,text width=3.5cm,
font=\ttfamily\bfseries,align=center,
},
}
\node[anchor=base east] (a) {default models};
\foreach \col/\txtcol in {blue/white,blue!1!cyan/black,cyan!99!blue/white,cyan/white}{
\node[block={\col}{\txtcol}](a){\col};
}
\node[anchor=base east] (a) at (0,-1) {rgb model};
\foreach \col/\txtcol in {rgbblue/white,rgbblue!1!rgbcyan/black,rgbcyan!99!rgbblue/black,rgbcyan/black}{
\node[block={\col}{\txtcol}](a){\col};
}
\node[anchor=base east] (a) at (0,-2) {cmy model};
\foreach \col/\txtcol in {cmyblue/white,cmyblue!1!cmycyan/white,cmycyan!99!cmyblue/white,cmycyan/white}{
\node[block={\col}{\txtcol}](a){\col};
}
\end{tikzpicture}
\end{document}
I don't know the details behind this, but blue!1!cyan
is not the same as cyan!99!blue
.
\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw[blue!1!cyan] (0,0) rectangle (-1,1);
\filldraw[cyan] (0,0) rectangle (1,1);
\filldraw[cyan!99!blue] (1,0) rectangle (2,1);
\end{tikzpicture}
\end{document}
No need to use \colorlet
. You can also specify directly the color model of the mix ... but anyway macho programmers use only wavelengths. :)
\documentclass{article}
\usepackage{xcolor}
\begin{document}
\colorbox{rgb:blue!1!cyan,1}{}
\colorbox{rgb:cyan!99!blue,1}{}
\colorbox[wave]{480}{}
\colorbox{cmy:blue!1!cyan,1}{}
\colorbox{cmy:cyan!99!blue,1}{}
\end{document}