[Tex/LaTex] Why do colours defined using CMYK give inconsistent results in TikZ mindmaps

colormindmapstikz-pgf

Background

I was trying to draw a mindmap using the tikz mindmap library for possible use in a beamer presentation.

The Problem

Depending on my choice of colours, the colour of nodes does not match the colours of the connectors linking them to other nodes. This is true whether the connections are automatically created using the mindmap's hierarchy or whether the connections are added manually afterwards in a \path operation.

MWE

This code demonstrates the problem. The first map is straight from page 662 of the manual and works fine. The second map is just like the first except that the colours used are different.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{mindmap}

\begin{document}

  \tikz[mindmap,concept color=blue!80]
    \node [concept] {Root concept}
    child[concept color=red,grow=30] {node[concept] {Child concept}}
    child[concept color=orange,grow=0] {node[concept] {Child concept}};

  \tikz[mindmap,concept color=magenta]
    \node [concept] {Root concept}
    child[concept color=cyan,grow=30] {node[concept] {Child concept}}
    child[concept color=yellow,grow=0] {node[concept] {Child concept}};

\end{document}

Mindmap colouring oddities

There are two problems:

  1. The node colours are not as expected. This is less obvious in the case of yellow but very obvious in the case of cyan and magenta.
  2. The colours are not consistent. That is, the connectors seem to use colours like those I would expect, even though the nodes do not. So the connectors do not flow smoothly to/from the nodes.

Investigation

The colours which work consistently are all defined using the RGB model. The colours which produce inconsistent results are all defined using the CMYK model. A work around is to define alternative colours in the RGB model. For example, to define a new colour, rgbmagenta just like magenta but in terms of rgb rather than cmyk.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{mindmap}
\definecolor{rgbmagenta}{rgb}{1,0,1}
\definecolor{rgbcyan}{rgb}{0,1,1}
\definecolor{rgbyellow}{rgb}{1,1,0}
\begin{document}

  \tikz[mindmap,concept color=rgbmagenta]
    \node [concept] {Root concept}
    child[concept color=rgbcyan,grow=30] {node[concept] {Child concept}}
    child[concept color=rgbyellow,grow=0] {node[concept] {Child concept}};

\end{document}

Mindmap with alternative colour definitions

Question

Why exactly does this happen? Can it be avoided without redefining colours as I did in the workaround?

I fear this question is surely a duplicate but searching has so far turned up nothing especially enlightening. I have found threads suggesting that TikZ may be converting colours from the CMYK model to RGB but while that might explain the colours not being quite as expected, it doesn't explain the inconsistencies.

Best Answer

TikZ (before version 3.1.3) uses RGB colors for color gradients.

With the package xcolor (required by tikz and beamer), you can:

  1. convert a CMYK color to a RGB color:

    \colorlet{yellow}[rgb]{yellow}
    
  2. convert a RGB color to a CMYK color:

    \colorlet{red}[cmyk]{red}
    

To always use RGB colors, pass the rgb option to xcolor:

\usepackage[rgb]{xcolor}

As beamer requires xcolor, you must pass this option before:

\PassOptionsToPackage{rgb}{xcolor}
\documentclass{beamer}
Related Question