23

I'm doing a poster with the baposter which uses tikz and at some point realized that some colors that should be identical are not. It turns out that tikz apparently resorts to RGB color space as soon as there is a shading involved, whereas I'm doing the poster (a I intend to print it...) in CMYK (which is also the default in the baposter class).

Now my question is: How do I force tikz to use CMYK everywhere?

Here's a minimal example that demonstrates the problem:

\documentclass{minimal}

%%% uncomment to use CMYK
\usepackage[cmyk]{xcolor}
\definecolor{mygreen}{cmyk}{1,0,0.57,0.42} 

%%% uncomment to use RGB
% \usepackage[rgb]{xcolor}
% \definecolor{mygreen}{HTML}{009440}

\usepackage{tikz}

\pdfcompresslevel=0

\begin{document}

\color{mygreen}{MY TEXT}

\tikz 
  \shade [left color=mygreen,right color=mygreen] 
  (1,1) rectangle (2,2);
%
\tikz 
  \fill [mygreen] 
  (1,1) rectangle (2,2);

\end{document}

The two boxes, which should have the same color, have not. The shaded box should have the same color as the solid box and the text.

(Note: this question is not so much about the baposter class, however, as baposter uses tikz the underlying problem leads to the fact that the frames of the boxes and the shadings in the header of the boxes have different colors.)

  • I might be wrong but TikZ doesn't know how to interpolate in different color models and relies on xcolor. – percusse Oct 7 '13 at 16:11
17

Unfortunately, the requested feature is unsupported.

In general, your approach works fine: if you write

\usepackage[cmyk]{xcolor}

all color definitions result in cmyk colors. But shadings are special: they are not based on xcolor's drivers but on pgf's drivers. And the pgf drivers for shadings supports RGB, nothing else. I believe that pgf calls colorspace conversion routines in order to convert from cmyk back to RGB whenever it generates shadings.

What you need is a feature request for PGF in order to respect the global xcolor configuration and to generate shadings in that color space.


There may be work-arounds. These, however, depend on the urgency - if you say that you will file feature requests and will live with the restriction, that is fine.

If you really need a workaround, you can continue reading.

The work-around that I have in mind is to use pgfplots. It has a couple of plot-related shadings and comes with its own related drivers. These, in turn, support cmyk - and most shadings can be expressed as plot-based shadings. The effort to convert these shadings from tikz pictures which have a super embedding into your pictures to pgfplots plots would be medium.

Here is an attempt in this direction:

\pdfcompresslevel=0
\documentclass{minimal}

%%% uncomment to use CMYK
\usepackage[cmyk]{xcolor}
\definecolor{mygreen}{cmyk}{1,0,0.57,0.42} 

\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

%%% uncomment to use RGB
% \usepackage[rgb]{xcolor}
% \definecolor{mygreen}{HTML}{009440}

\usepackage{tikz}


\begin{document}

\color{mygreen}{MY TEXT}

\tikz 
  \shade [left color=mygreen,right color=mygreen] 
  (1,1) rectangle (2,2);
%
\tikz 
  \fill [mygreen] 
  (1,1) rectangle (2,2);

\begin{tikzpicture}
    % this statement is needed for pgfplots v1.8. 
    % pgfplots 1.9 or newer inherits it from
    % \usepackage[cmyk]{xcolor}:
    \pgfplotsset{mesh/colorspace explicit color output=cmyk}

    \begin{axis}[
        x=1cm,y=1cm,
        hide axis,
        view={0}{90}]
    \addplot[surf,mesh/color input=explicit,shader=interp] 
    table[meta=cdata] {
        x y cdata
        1 1 color=mygreen
        2 1 color=yellow

        1 2 color=mygreen
        2 2 color=yellow
    };
    \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

It relies on a surface plot with explicit color using the rectangular coordinates (1cm,1cm) (2cm,2cm) and the colors are listed in the table. The verbose syntax color=<name> is necessary to distinguish from something like 0,0,1 or gray=0.5.

  • My follow-up question would be how to use pgfplots to do the background shading in the baposter class. – fuenfundachtzig Oct 8 '13 at 20:26
  • hm. Would it help if something like \shade [left color=mygreen,right color=mygreen] would be expressed by means of a pgfplots shading? Otherwise you would need to compose a(nother) minimal working example illustrating the problem. – Christian Feuersänger Oct 8 '13 at 20:31
  • I have edited my answer with an initial attempt. This illustrates what would need to be done and can (hopefully) be generalized to what you need in your poster. – Christian Feuersänger Oct 8 '13 at 20:49
  • Still, a feature request for tikz/pgf would be a good idea. – Christian Feuersänger Oct 8 '13 at 20:50
  • I'm surprised this works: As pgfplots is based on tikz why can it do shadings "better" than tikz itself? And as it apparently can do: Can't I just use how pgfplots does the shading directly? (And yes, that would be helpful as I'd need to translate the shadedraw command.) – fuenfundachtzig Oct 9 '13 at 8:33
5

It's quite late for the OP, but if someone faces this problem, there is now a package (pgf-cmykshadings) that does just that. According to its documentation "The pack­age at­tempts to pro­duce shad­ings con­sis­tent with the cur­rently se­lected xcolor colour model. The rgb, cmyk, and gray colour mod­els from the xcolor pack­age are sup­ported."

MWE

Here's a MWE demonstrating how to use pgf-cmykshadings to produce a CMYK shading as asked in the question. You need to load pgf-cmykshadings before tikz for the shadings to be set up correctly. It's a good idea to load xcolor with the cmyk option before pgf-cmykshadings to ensure that all colours will be output in CMYK and there will be no colour mismatches.

\documentclass{minimal}
\usepackage[cmyk]{xcolor}
\definecolor{mygreen}{cmyk}{1,0,0.57,0.42} 
\usepackage{pgf-cmykshadings}
\usepackage{tikz}
\begin{document}
\color{mygreen}{MY TEXT}
\bigskip

\tikz 
  \shade [left color=mygreen,right color=mygreen] 
  (1,1) rectangle (2,2);
%
\tikz 
  \fill [mygreen] 
  (1,1) rectangle (2,2);
\bigskip

\tikz
  \shade [left color=cyan, right color=magenta]
  (1,1) rectangle (5,2);
\end{document}

enter image description here

  • 1
    Thanks! pgf-cmykshadings is indeed designed to answer this question (I'm the author). The original question can be solved by modifying the MWE to load pgf-cmykshadings after xcolor, but before tikz. You will then get CMYK colours everywhere, including in shadings. All LaTeX engines and drivers are supported in v1.1 (v1.0 didn't support dvips). – David Purton Oct 24 '18 at 1:07
  • Actually, please use at least v1.1a (I missed a missing percent sign!) in the first two versions uploaded to CTAN. :( – David Purton Oct 24 '18 at 2:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.