Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  Andrew Stacey Jan 12 '12 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) –  Andrew Stacey Jan 12 '12 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. –  Andrew Stacey Jan 12 '12 at 9:31
    
That did the trick. Thanks –  Christian Wolf Jan 12 '12 at 9:56
add comment

3 Answers

up vote 5 down vote accepted

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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