17

I have the following code:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{scopes,patterns,intersections,calc}
\begin{document}
\begin{tikzpicture}[thick]
        \path (-2,0) coordinate (t1) (2,0) coordinate (t2);
        \path (0,-2) coordinate (s1) (0,2) coordinate (s2);
        { [color=blue!50!red!50,pattern color=blue!50!red!50]
            \draw (s1) -- (s2);
            \path [pattern=north west lines] (s1) +(-0.2,0) rectangle (s2);
        }
        { [color=magenta,pattern color=magenta]
            \draw (t1) -- (t2);
            \path [pattern=north east lines] (t1) +(0,-0.2) rectangle (t2);
        }
\end{tikzpicture}
\end{document}

As in the first (vertical) scope I would expect that the pattern has the same color as the line in both scopes. For me, I get three different colors; the pattern and the main line of the horizontal scope differ quite much (looks nearly midway between colors of hor. and vert. scope).

screenshot

I am using pdfLaTeX to compile the file. Different viewers don't change anything.

Can you explain me this behavior?

3
  • Could you upload a screenshot, and say which version of TikZ/PGF that you are using? When I compile your code then I get the same colour for the lines as their respective patterns. Jan 12, 2012 at 9:25
  • I stand corrected! The effect is a little more subtle than I was expecting and I had to zoom in quite far to see it. (A screenshot would still be useful) Jan 12, 2012 at 9:26
  • 2
    I don't know why this is happening, but it seems to be the line colour that is wrong. I find I can fix it by loading xcolor with the svgnames package and using the colours defined by that, whence Magenta instead of magenta. Jan 12, 2012 at 9:31

3 Answers 3

14

I'm not a great expert with color and latex but I think magenta is defined somewhere with the rgb system by (1,0,1) . With color=magenta magenta is not defined by rgb(1,0,1) but something like rgb (0.79216,0.12156,0.48236). Then when you use the pattern, pgf/tikz uses extra tools to convert the color in a rgb color and you get finally in all cases rgb(1,0,1). A possible solution is to define yourself magenta with \definecolor{magenta}{rgb}{1,0,1} or with \definecolor{magenta}{rgb}{0.79216,0.12156,0.48236} or something like that. In the first case the color for the line is rgb (1,0,1)and it's the same for the pattern and in the second case the conversion with \convertcolorspec gives your definition rgb(0.79216,0.12156,0.48236).

\documentclass{minimal}  
%\usepackage[dvipsnames]{xcolor} 
\usepackage{tikz}
\usetikzlibrary{scopes,patterns,intersections,calc}
\begin{document} 

%\definecolor{magenta}{rgb}{1,0,1} 
\definecolor{magenta}{rgb}{0.79216,0.12156,0.48236}    

\begin{tikzpicture}[thick]
        \path (-2,0) coordinate (t1) (2,0) coordinate (t2);
        \path (0,-2) coordinate (s1) (0,2) coordinate (s2);
        { [color=blue!50!red!50,pattern color=blue!50!red!50]
            \draw (s1) -- (s2);
            \path [pattern=north west lines] (s1) +(-0.2,0) rectangle (s2);
        }
        { [color=magenta,pattern color=magenta]
            \draw (t1) -- (t2);
            \path [pattern=north east lines] (t1) +(0,-0.2) rectangle (t2);
        }
\end{tikzpicture}
\end{document}

enter image description here

1
  • Please don't use minimal for examples.
    – cfr
    Apr 19, 2015 at 0:31
4

Not sure if anyone else has noticed this, but I found that tinting a colour leads to a different colour in TikZ (in pgfplots, at least). E.g. if I paint something black, it comes out black, but if I paint something black!100!black it comes out as a dark grey. Not sure why, I guess it's a bug.

Anyway, I noticed you use colour tints in your code, so maybe it's affecting you too.

2

This issue can also be resolved by explicitly loading the xcolor package with the rgb option before loading the tikz package (the loading order is important as tikz implicitly loads xcolor and that leads to an option clash when xcolor is loaded after tikz). But this will have the side effect that all colors in your document are converted to the rgb model. As long as you're fine with that this should solve your problem.

You must log in to answer this question.

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