5

Background: I am using tcolorbox to build my theorem, definition, and example environments. I've been using a shading for the background of these environments, but recently learned that the shading in pgf is hard-coded to RGB, but I have to use CMYK for printing purposes.

pgfplots is capable of doing shading in CMYK colorspace, see here.

Problem: tcolorbox appears to use pgf to do its shading. Is it possible to instead have tcolorbox use pgfplots to do its shading, preferably in an automatic way?

For example, here's an MWE:

\documentclass{article}
\usepackage[cmyk]{xcolor}
\usepackage[many]{tcolorbox}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\tcbset{
definitionstyle/.style={%
enhanced,
interior style={left color=black!2, right color=blue!30}
}
}   

\begin{document}

\begin{tcolorbox}[definitionstyle]
Blah blah
\end{tcolorbox}

\end{document}

I'd like to replace the left color=black!2, right color!30 with something like

\begin{tikzpicture}
\begin{axis}[x=1cm,y=1cm,hide axis]
\addplot[surf,mesh/color input=explicit,shader=interp] 
table[meta=cdata]{
x y cdata
1 1 color=black!2
2 1 color=blue!30

1 2 color=black!2
2 2 color=blue!30
};
\end{axis}
\end{tikzpicture}

which would do the shading in pgfplots with CMYK colors.

3 Answers 3

5

The TikZ \shade command can be used in an underlay, for example. I don't think pgfplots is necessary here.

Don't forget to use \begin{tcbclipinterior}...\end{tcbclipinterior} to get the correct clipping of the shading.

\documentclass{article}
\usepackage[cmyk]{xcolor}
\usepackage[many]{tcolorbox}

\tcbset{
definitionstyle/.style={%
  enhanced,
  underlay={\begin{tcbclipinterior}
      \shade[left color=black!2, right color=blue!30] (interior.north west) rectangle (interior.south east);
    \end{tcbclipinterior} 
  },
}
}   

\begin{document}

\begin{tcolorbox}[definitionstyle]
Blah blah
\end{tcolorbox}

\end{document}
1
  • I had misunderstood what worked in pgfplots to output in CMYK and have updated the question to accurately reflect what actually works. I like your idea behind using an underlay with tcbclipinterior, but the shading as written outputs in RGB. I tried to replace that with the pgfplots shading (see the updated question) but it doesn't compile (complains of runaway argument, extra }, pgf math error, illegal unit of measure, etc).
    – Hayden
    Jul 26, 2017 at 13:19
1

(Warning: Very Hacky solution)

Using Christian's idea of tcbclipinterior and underlay, I came up with the following way of making sure that everything is CMYK.

Firstly, the following code is used to produce a page which is entirely shading:

\pdfcompresslevel=0
\documentclass{minimal}

\usepackage[cmyk]{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{tikz}

\addtolength{\oddsidemargin}{-1.5in}
\addtolength{\evensidemargin}{-1.5in}
\addtolength{\textwidth}{1.5in}
\addtolength{\topmargin}{-1.5in}
\addtolength{\textheight}{1.75in}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[xmin=0, ymin=0, x=9in,y=13in, hide axis]
    \addplot[surf,mesh/color input=explicit,shader=interp] 
    table[meta=cdata] {
        x y cdata
        0 0 color=black!4
        1 0 color=teal!20

        0 1 color=black!4
        1 1 color=teal!20
    };
    \end{axis}
\end{tikzpicture}
\end{document}

The output has an extra blank page at the front, so remove that (I printed the second page as a PDF only, then I selected Preflight and perform "Analyze and Fix" (this step is done because otherwise there will be "device independent colors" which arise later). Let's say the final result is the file background.pdf. Then we can do the following:

\documentclass{article}
\usepackage[cmyk]{xcolor}
\usepackage[many]{tcolorbox}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{graphicx}
\usepackage{lipsum}

\tcbset{
definitionstyle/.style={%
  enhanced,
  underlay={
    \begin{tcbclipinterior}
    \includegraphics{background.pdf}
    \end{tcbclipinterior} 
  }
}
} 

\begin{document}

\begin{tcolorbox}[definitionstyle]
\lipsum[1]
\end{tcolorbox}

\end{document}

This will produce a pdf with no RGB.

An additional comment I will make is that if you're using any nodes (as I was), you can add \tcbuselibrary{skins} and then add fill plain image=background.pdf to the options for the node.

1

This question was asked quite a time ago, but I think I have a new answer for it.

I follow the original idea of replacing the conventional shading by a pgfplots shading. The axis environment of pgfplots is used inside fill overzoom picture to be scaled into the given node, here, the background of a tcolorbox.

Unfortunately, the code cannot applied directly into the new style definitionstyle cmyk for some technical reasons (at least I could'nt do it). I guess (but do not know) that the code is scanned as verbatim by pgfplots. My clumsy but working solution is to save the code in a file and input that file at the required place.

The complete example is:

\documentclass{article}
\usepackage[cmyk]{xcolor}
\usepackage[many]{tcolorbox}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{tcbverbatimwrite}{\jobname_myshading.tex}
\begin{axis}[x=1cm,y=1cm,hide axis]
\addplot[surf,mesh/color input=explicit,shader=interp]
table[meta=cdata]{
x y cdata
1 1 color=black!2
2 1 color=blue!30

1 2 color=black!2
2 2 color=blue!30
};
\end{axis}
\end{tcbverbatimwrite}

\tcbset{
  definitionstyle/.style={%
    enhanced,
    interior style={left color=black!2, right color=blue!30}
  },
  definitionstyle cmyk/.style={%
    enhanced,
    interior style={fill overzoom picture={\input{\jobname_myshading.tex}}}
  },
}

\begin{document}

\begin{tcolorbox}[definitionstyle]
Shading RGB
\end{tcolorbox}

\begin{tcolorbox}[definitionstyle cmyk]
Shading CMYK via pgfplots
\end{tcolorbox}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .