5

The MWE says it all:

% !TeX program = LuaLaTeX
% !TeX encoding = UTF-8
\documentclass{minimal}
\PassOptionsToPackage{monochrome}{xcolor}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
  \selectcolormodel{gray}
  \filldraw[draw=red,fill=red] (1.5,4) rectangle (3.5,4.5);
  \end{tikzpicture}
\end{document}

It draws the box. But the box is red. I expect it to be gray. Same with LuaLaTeX or pdfLaTeX compiler. TeXlive 2016 on Linux. Interface is TeXworks.

My first attempt with TikZ bombed. :(

  • (1) xcolor plays almost almost no role in TikZ; I am not surprise if a command from xcolor does not work. (2) What exactly do you want? If you want a gray rectangle, you should try fill=gray or fill=black!50. (3) \PassOptionsToPackage{gray}{xcolor}. – Symbol 1 Oct 23 '16 at 22:01
  • 2
    I am attempting to force TikZ to grayscale, even if drawn in color. I know how to draw gray directly. That is not the problem. An earlier question from someone else had reference to xcolor, so I threw that in for good measure. Passing gray (instead of monochrome) to xcolor did the trick. I had also tried grayscale, which didn't work. Just gray works. – user103221 Oct 23 '16 at 22:10
  • 1
    It's curious. It works as expected for \fill[red] (2,0) circle (1);, but \fill[fill= red] (2,0) circle (1); gives a red circle. It looks as if the key bypasses the color conversion. – Ulrike Fischer Oct 23 '16 at 22:27
  • 1
    note that monochrome option to (x)color doesn't give greyscale, it disables colour completely so you get full black for all text or rules. – David Carlisle Oct 23 '16 at 22:35
  • Ah, but if monochrome disabled color completely, then I would not see a red rectangle, with my original code. I'd see black or white. – user103221 Oct 23 '16 at 22:39
5

Use the \fill[red,draw=red] instead.

Note: Besides the comments by @Symbol1, avoid using the minimal class.

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\selectcolormodel{gray}
\fill[red,draw=red] (1.5,4) rectangle (3.5,4.5);
\end{tikzpicture}

\end{document}

enter image description here

EDIT:

To get all strokes as well as all fills grayscale-colored, the \usepackage[gray]{xcolor} option can be used. It will, however, set this in the whole document except for the included graphics.

\documentclass[border=2pt]{standalone}
\usepackage[gray]{xcolor}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\fill [draw=blue,fill=red] (1.5,4) rectangle (3.5,4.5);
\draw [fill=green,draw=red] (1,2)--(1,3)--(3,3)--cycle;
\end{tikzpicture}

\end{document}

enter image description here

  • I get red from this – David Carlisle Oct 23 '16 at 22:19
  • @DavidCarlisle - It gives me gray on my machine and on ShareLaTeX as well. I wonder if someone else is having the same issue! – AboAmmar Oct 23 '16 at 22:28
  • 1
    Hmm.. Shouldn't the border and fill both be gray, if that is the color model? The above image shows a red border with gray fill. My objective is to prevent the insertion of a color drawing in a document that must be grayscale (it can be reduced to gray). – user103221 Oct 23 '16 at 22:36
  • 1
    as shown in the image, the fill is gray but the drawn border is red – David Carlisle Oct 23 '16 at 22:36
  • Plenty of good feedback. Symbol1 didn't write his comment as an answer, so I'll mark this one. Still, I see that others experience odd behavior. In my case, I really do wish to disable color everywhere (except included images, which cannot be treated that way). I got the monochrome from something else, long ago (and yes, it was black and white). – user103221 Oct 23 '16 at 23:45
3

You can force the pgf color commands to use gray or any other colour that you want:

\documentclass{minimal}
%\PassOptionsToPackage{monochrome}{xcolor}
\usepackage{tikz}
\let\oldpgfsetstrokecolor\pgfsetstrokecolor
\let\oldpgfsetfillcolor\pgfsetfillcolor
\def\pgfsetstrokecolor#1{\oldpgfsetstrokecolor{gray}}
\def\pgfsetfillcolor#1{\oldpgfsetfillcolor{gray}}

\begin{document}
  \begin{tikzpicture}
  \selectcolormodel{gray}
  \filldraw[draw=red,fill=red] (1.5,4) rectangle (3.5,4.5);
  \end{tikzpicture}
\end{document}
  • 1
    Please don't use minimal for examples!! – cfr Oct 24 '16 at 1:19
  • @cfr I'm allowed to use my own class files, surely:-) – David Carlisle Oct 24 '16 at 8:25
  • Allowed, sure, but you should surely include a health warning? – cfr Oct 24 '16 at 16:41
3

The monochrome option is inherited from the old color package. Description: One special option for the color package that is of interest is monochrome. If this option is selected the colour commands are all disabled so that they do not generate errors, but do not generate colour either. This is useful if previewing with a previewer that can not produce colour.

Here, you want colors in a gray space, so you may use the gray option of xcolor package:

\documentclass{standalone}
\PassOptionsToPackage{gray}{xcolor}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \filldraw[draw=red,fill=green] (1.5,4) rectangle (3.5,4.5);
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

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