tikz add tag
samcarter
This problem came up in https://github.com/josephwright/beamer/issues/718 . In other colour models (like `rgb`, `gray` etc.) the following code would result in a transparent rectangle. However in `cmyk` it results in a baby pink shape.

Is there any way to create a transparent fading in `cmyk`?

```
\documentclass{standalone}

\usepackage{pgf}
\selectcolormodel{cmyk}

\pgfdeclareverticalshading{myshade}{3cm}{%
  color(0ex)=(pgftransparent!100);%
  color(1ex)=(pgftransparent!100)
}
\pgfdeclarefading{mymask}{\pgfuseshading{myshade}}

\begin{document}

\fbox{\begin{pgfpicture}
  \pgfsetfillcolor{red}%
  \pgfpathrectangle{\pgfpoint{0pt}{-1ex}}{\pgfpoint{3cm}{1.2ex}}%
  \pgfsetfading{mymask}{\pgftransformscale{2}}%
  \pgfusepath{fill}%
\end{pgfpicture}}

\end{document}
```

![document.png](/image?hash=0b21d0f45e94361d9201699c5f2f91ce3e052f9744ea54f2bd83572b6501016e)
Top Answer
samcarter
@zauguin explains where the problem comes from:

> At least for pdf.js and Poppler's cairo backend the underlying issue is that Luminosity softmasks are always calculated in RGB (independent of the colorspace specified for the transparency group) and the used CMYK to RGB conversion does not preserve black.

(quote from https://github.com/pgf-tikz/pgf/issues/1057#issuecomment-939081615)

Thankfully @hmenke and @dcpurton had a suggestion for a workaround: one can use another color model for defining the fading.

The following hack seems to work fine:


```
\documentclass{standalone}

\usepackage{pgf}
\selectcolormodel{cmyk}

{
\selectcolormodel{gray}
\pgfdeclareverticalshading{myshade}{3cm}{%
  color(0ex)=(pgftransparent!0);%
  color(1ex)=(pgftransparent!100)
}
\pgfdeclarefading{mymask}{\pgfuseshading{myshade}}
}

\begin{document}

\fbox{\begin{pgfpicture}
  \pgfsetfillcolor{red}%
  \pgfpathrectangle{\pgfpoint{0pt}{-1ex}}{\pgfpoint{3cm}{2ex}}%
  \pgfsetfading{mymask}{\pgftransformxscale{2}}%
  \pgfusepath{fill}%
\end{pgfpicture}}

\end{document}
```

![document.png](/image?hash=6e3d97271a4953e2964ca250d6893a507c806f008f3e55b3fad79518460fb199)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.