# Beamer Block gradient (bmg@transition) and cmyk colors

This question is related to remove Beamer block transition between title and body and How to disable color gradient between block title and block body in Beamer? but is not a duplicate of these particular two questions.

Let us consider the following minimal example:

\documentclass{beamer}
\usepackage{etoolbox}
\definecolor{top}{cmyk}{1,0,0,0}
\colorlet{bottom}{top!10!white}

\BeforeBeginEnvironment{block}{
\setbeamercolor{block title}{fg=white,bg=top}
\setbeamercolor{block body}{fg=black, bg=bottom}
}
\AfterEndEnvironment{block}{
\setbeamercolor{block title}{use=structure,fg=structure.fg,bg=structure.fg!20!bg}
\setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!50!bg, fg=black}
}

\makeatletter
color(0pt)=(lower.bg); color(4pt)=(lower.bg); color(4pt)=(upper.bg)}
\makeatother

\begin{document}
\begin{frame}
\begin{block}{Block}
Block stuff.
\end{block}
\end{frame}
\end{document}


It will produce the output:

So, there you might notice that the transition line between the title and body part of the block (where usually the gradient is shown) is neither of the top nor of the bottom colour, but somewhere in between.

If we modify the defintion of the color top to an rgb-based color, e.g \definecolor{top}{rgb}{1,0,0}, then the approach works as desired (that is, there is no line in a different colour visible in between):

Why does this happen for the cmyk colour model only?

• The problem roughly boils down that the calculation of the shading assumes one colour space, but beamer does not really set it but just uses the colour space of the first colour - or something along these lines. Every time I tried to take a deeper look into this it resulted in a massive headache... – samcarter is at topanswers.xyz Oct 1 '18 at 15:21
• (using a red block to show that the problem vanished is a bit unfortunate, because red is one of the colours where the difference between rgb and cmyk is hardly visible, better examples would be cyan or green) – samcarter is at topanswers.xyz Oct 1 '18 at 15:27
• – samcarter is at topanswers.xyz Oct 1 '18 at 15:34
• I think the core problem is that pgf shadings do not support CMYK. There are some workarounds noted on this site, e.g., tex.stackexchange.com/q/388520/87678. But I don't know how to apply this to beamer. Do you really need CMYK for slides, though? – David Purton Oct 2 '18 at 5:11
• To more clearly see what is going on use \documentclass[cmyk]{beamer} to pass cmyk to xcolor (and so try to always output CMYK). Then define your colours like this: \definecolor{top}{cmyk}{1,0,1,0} and \definecolor{bottom}{cmyk}{1,0,0,0}. Then remove your pgfdeclareverticalshading line. You will see the top part of the box is CMYK green, the bottom is CMYK cyan. But the gradient is RGB, even though in theory everything should be CMYK. – David Purton Oct 2 '18 at 5:33

# Update

pgf now supports CMYK shadings since version 3.1.3. So it is no longer necessary to use pgf-cmykshadings. (You still need to use \RequirePackage[cmyk]{xcolor} to use CMYK shadings by default.)

What you are seeing happens because PGF shadings do not support CMYK. So even though you have specified top and bottom colours in CMYK, they are converted to RGB for the gradient. This happens even if you change the gradient to start and end with the same colour.

# Update

There is now a new alternative to solving this problem. You can use the pgf-cmykshadings package which supports CMYK shadings in pgf. Change the start of the MWE in the question to this:

\RequirePackage[cmyk]{xcolor}
\documentclass{beamer}


It is necessary to load pgf-cmykshadings before beamer for shadings to be defined in CMYK. I've also loaded xcolor with the cmyk option to ensure all colours will be in the same (CMYK) colour space.

A workaround in your case is to patch the \beamerboxesrounded macro from beamerbaseboxes.sty to use a solid filled rectangle instead of the gradient. This can be any colour you like. Here, I've set it to the bottom colour of the box as in your question.

# MWE

\documentclass{beamer}
\definecolor{top}{cmyk}{1,0,0,0}
\colorlet{bottom}{top!10!white}

\BeforeBeginEnvironment{block}{
\setbeamercolor{block title}{fg=white,bg=top}
\setbeamercolor{block body}{fg=black, bg=bottom}
}
\AfterEndEnvironment{block}{
\setbeamercolor{block title}{use=structure,fg=structure.fg,bg=structure.fg!20!bg}
\setbeamercolor{block body}{parent=normal text,use=block title,bg=block title.bg!50!bg, fg=black}
}

% patch \beamerboxesrounded from beamerbaseboxes.sty to use solid colour
\makeatletter
\usepackage{xpatch}
\xpatchcmd{\beamerboxesrounded}
{\pgfpathrectangle{\pgfpoint{-4bp}{-1bp}}{\pgfpoint{\bmb@dima}{8bp}}
\pgfusepath{clip}
{\pgfpathrectangle{\pgfpoint{-4bp}{0bp}}{\pgfpoint{\bmb@dima}{4bp}}
\pgfsetcolor{lower.bg}
\pgfusepath{fill}}
{}
{}
\makeatother

\begin{document}
\begin{frame}
\begin{block}{Block}
Block stuff.
\end{block}
\end{frame}
\end{document}