图案颜色与正常颜色不同吗?

图案颜色与正常颜色不同吗?

我有以下代码:

\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}

和第一个(垂直)示波器一样,我期望图案的颜色与两个示波器中的线条相同。对我来说,我得到了三种不同的颜色;图案和水平示波器的主线差别很大(看起来几乎介于水平和垂直示波器颜色的中间)。

截屏

我使用 pdfLaTeX 编译文件。不同的查看器不会改变任何内容。

你能向我解释一下这种行为吗?

答案1

我不是颜色和乳胶方面的专家,但我认为洋红色在 rgb 系统的某个地方定义为 (1,0,1)。color=magenta洋红色不是由 rgb(1,0,1) 定义的,而是类似于的rgb (0.79216,0.12156,0.48236)。然后当您使用该模式时,pgf/tikz 会使用额外的工具将颜色转换为 rgb 颜色,最终在所有情况下都会得到 rgb(1,0,1)。一种可能的解决方案是magenta使用 \definecolor{magenta}{rgb}{1,0,1}或使用 \definecolor{magenta}{rgb}{0.79216,0.12156,0.48236}或类似的东西来定义自己。在第一种情况下,线条的颜色为,rgb (1,0,1)并且对于图案来说也是相同的,在第二种情况下,使用 进行转换\convertcolorspec会给出您的定义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}

在此处输入图片描述

答案2

不确定是否有人注意到了这一点,但我发现在 TikZ 中给某种颜色着色会导致颜色发生变化(pgfplots至少在 中)。例如,如果我画某样东西black,它会变成黑色,但如果我画某样东西,black!100!black它会变成深灰色。不知道为什么,我猜这是一个错误。

无论如何,我注意到您在代码中使用了色调,所以也许它也会影响您。

答案3

也可以通过使用选项显式加载xcolor包来解决此问题rgb加载tikz包(加载顺序很重要,因为会tikz隐式加载,这会导致在加载后发生xcolor选项冲突)。但这会产生副作用,即文档中的所有颜色都会转换为 rgb 模型。只要您同意,这应该可以解决您的问题。xcolortikz

相关内容