3

My code follows:

\documentclass[]{book}
\usepackage[]{tikz}
\usetikzlibrary{positioning}
\input colordvi
\input cmyk-hax
\makeatletter
\definecolor{testcolor}{cmyk}{0,0,0,0.1}
\pgfutil@colorlet{tikz@ball}{testcolor}
\pgfdeclareradialshading[testcolor]{ball}{\pgfqpoint{-10bp}{10bp}}{%
 color(0bp)=(testcolor!15!white);
 color(9bp)=(testcolor!75!white);
 color(18bp)=(testcolor!70!black);
 color(25bp)=(testcolor!50!black);
 color(50bp)=(black)}
\makeatother

\begin{document}

\hspace*{-1pc}\vbox{
\begin{centering}
\newlength\radius
\pgfmathsetlength{\radius}{0.25cm}
\newcommand\drawballs[2][]{%
    \foreach \y [evaluate=\y as \yy using #2+1-\y] in {1,...,#2} {%
        \foreach \x in {1,...,\yy} {%
            \shade[shading=ball,ball color=white,#1]
                ({(2*\x-2+\y)*\radius},{sqrt(3)*\y*\radius}) circle (\radius);
        };
    }%
}


\begin{tikzpicture}
%    \drawballs{1}
%    \drawballs[xshift=1.5cm]{2}
%    \drawballs[xshift=4cm]{3}
%    \drawballs[xshift=7cm]{4}
%    \drawballs[xshift=10cm]{5}
    \drawballs[xshift=2cm]{1}
    \drawballs[xshift=3.5cm]{2}
    \drawballs[xshift=5.5cm]{3}
    \drawballs[xshift=8cm]{4}
    \drawballs[xshift=11cm]{5}
\end{tikzpicture}
\end{centering}
}


\end{document}

This code works well and the output generated successfully. But shaded part shows the mixing color of CMYK combination, but my requirement shade variation should show only B/W. Kindly suggest how can achieve this?

6
  • 1
    Maybe with \definecolor{testcolor}{gray}{0.9} if I understand your question correctly?
    – Max
    Jul 30, 2018 at 5:55
  • @MaxSnippe Thanks for your quick suggestion, but still the problem exists....
    – MadyYuvi
    Jul 30, 2018 at 6:41
  • What then is exactly your problem?
    – Max
    Jul 30, 2018 at 6:43
  • 1
    Well, @MaxSnippe tried to politely tell you that your question is not as clear as it could (or even should) be. Could you please try to make a more precise version?
    – user121799
    Jul 30, 2018 at 6:44
  • I think this is because pgf gradients do not support CMYK. They get converted to RGB, which messes everything up. Jul 30, 2018 at 13:30

1 Answer 1

4

Update

tikz now supports grayscale and CMYK shadings since version 3.1.3. So it is only necessary to use \usepackage[gray]{xcolor} (or \usepackage[cmyk]{xcolor}) before loading tikz.


The fundamental problem is that pgf shadings do not support CMYK. So even though you define your testcolor colour in CMYK, it gets converted to RGB in the radial shading in your spheres.

Then when you try to output separations, you find that the RGB gray separates out onto all four plates instead of just the black plate.

This can be solved using a new package, pgf-cmykshadings, which supports CMYK (and grayscale) shadings.

Change the start of your MWE to:

\documentclass{book}
\usepackage[gray]{xcolor}% (could also use \usepackage[cmyk]{xcolor})
\usepackage{cmyk-shadings}
\usepackage{tikz}
\usetikzlibrary{positioning}
\input colordvi
\input cmyk-hax

pgf-cmykshadings will work with all LaTeX engines, so if you don't need cmyk-hax, you could drop it (and colordiv) and use pdflatex, xelatex, or lualatex.

This will result in a PostScript (or PDF) file which only uses the black plate.

1
  • Thanks for your effort, will check and get back to you, hence I'm in traveling ...
    – MadyYuvi
    Oct 25, 2018 at 13:14

You must log in to answer this question.

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