我的标签如下:
\documentclass{book}
\usepackage{tikz,amsmath,caption,subcaption}
\usetikzlibrary{arrows,patterns}
%\usepackage{fullpage,varwidth}
\tikzset{transform shape}
\usetikzlibrary{knots}
\usepackage{graphicx}
\begin{document}
\begin{figure}[t]\vspace*{5pt}
\centering
\begin{tikzpicture}[scale=0.6]
% \draw[step=1cm,color=gray!30] (-7,-5) grid (7,5);
\begin{scope}
\draw[clip] (-4,0) ellipse (2 and 5);
\filldraw[thick, pattern color=gray!90, pattern=vertical lines] (-6,0) -- (-2,0) --(-2,5) -- (-6,5)--cycle;
\filldraw[thick, pattern color=gray!90, pattern=horizontal lines] (-6,0) -- (-2,0) --(-2,-5) -- (-6,-5)--cycle;
\end{scope}
\draw[thick] (-4,0) ellipse (2 and 5);
\draw[thick] (4,0) ellipse (2 and 5);
\draw[thick] (2,0) -- (6,0);
\node at (-4,4) {{\Huge \boldmath $C$}};
\node at (-4,-4) {{\Huge \boldmath $\bar {C \rule{0pt}{18pt}}$}};
\node at (4,4) {{\Huge \boldmath $D$}};
\node at (4,-4) {{\Huge \boldmath $\bar {D \rule{0pt}{18pt}}$}};
\filldraw[pattern color=gray!90, pattern=vertical lines] (3.5,1) to[out=180, in=180] (4,2)
to[out=0,in=0] (4.5,.7)
to[out=180, in=45] (4,.4)
to[out=180,in=0] cycle
;
\draw[dashed] (-3.75,4.97) -- (4,2);
\draw[dashed] (-2,0) -- (4,.4);
\filldraw[pattern color=gray!90, pattern=horizontal lines] (4,-1) to[out=0,in=180] (4.5,-1.5)
to[out=0,in=0] (4.5,-2)
to[out=180,in=45] (4,-2.5)
to[out=225,in=180,looseness=1.5] cycle
;
\draw[dashed] (-2,0) -- (4,-1);
\draw[dashed] (-3.8,-4.97) -- (3.85,-2.6);
\draw[thick, ->] (-1.5,1.5) -- (1.5,1.5) node[pos=.5,above] {\LARGE $f$};
\draw[thick, ->] (-1.5,-2) -- (1.5,-2) node[pos=.5,below] {\LARGE $f$};
\end{tikzpicture}
\caption{A schematic illustration of a reduction between two classification problems.}
\end{figure}
\end{document}
它运行良好,但垂直和水平线颜色显示为 CMYK 组合,但它应该只显示黑色,参考图像如下:
如果我检查规则颜色,那么它会显示灰色是 CMYK 值的混合,请参考下图进行说明:
但它应该只显示黑色值,请建议...
答案1
有一个简单的方法可以解决这个问题,而无需添加对 CMYK/灰色无色图案的支持。
您可以声明天生有色图案定义中包含颜色。这些图案不限于 RGB,因此您可以创建仅出现在黑色分色上的图案。
在下面的 MWE 中,我声明了两个新模式(gray vertical lines
和)。其定义与和gray horizontal lines
相同,只是包含了一个描边颜色,并且使用而不是来声明它们vertical lines
horizontal lines
\pgfdeclarepatterninherentlycolored
\pgfdeclarepatternformonly
平均能量损失
\documentclass{book}
\usepackage{xcolor}
\usepackage{tikz,amsmath,caption,subcaption}
\usetikzlibrary{arrows,patterns}
\tikzset{transform shape}
\usetikzlibrary{knots}
\usepackage{graphicx}
\pgfdeclarepatterninherentlycolored{gray horizontal lines}{\pgfpointorigin}{\pgfqpoint{100pt}{1pt}}{\pgfqpoint{100pt}{3pt}}%
{
\pgfsetstrokecolor{gray!90}
\pgfsetlinewidth{0.4pt}
\pgfpathmoveto{\pgfqpoint{0pt}{0.5pt}}
\pgfpathlineto{\pgfqpoint{100pt}{0.5pt}}
\pgfusepath{stroke}
}
\pgfdeclarepatterninherentlycolored{gray vertical lines}{\pgfpointorigin}{\pgfqpoint{1pt}{100pt}}{\pgfqpoint{3pt}{100pt}}%
{
\pgfsetstrokecolor{gray!90}
\pgfsetlinewidth{0.4pt}
\pgfpathmoveto{\pgfqpoint{0.5pt}{0pt}}
\pgfpathlineto{\pgfqpoint{0.5pt}{100pt}}
\pgfusepath{stroke}
}
\begin{document}
\begin{figure}[t]\vspace*{5pt}
\centering
\begin{tikzpicture}[scale=0.6]
% \draw[step=1cm,color=gray!30] (-7,-5) grid (7,5);
\begin{scope}
\draw[clip] (-4,0) ellipse (2 and 5);
\filldraw[thick, pattern=gray vertical lines] (-6,0) -- (-2,0) --(-2,5) -- (-6,5)--cycle;
\filldraw[thick, pattern=gray horizontal lines] (-6,0) -- (-2,0) --(-2,-5) -- (-6,-5)--cycle;
\end{scope}
\draw[thick] (-4,0) ellipse (2 and 5);
\draw[thick] (4,0) ellipse (2 and 5);
\draw[thick] (2,0) -- (6,0);
\node at (-4,4) {{\Huge \boldmath $C$}};
\node at (-4,-4) {{\Huge \boldmath $\bar {C \rule{0pt}{18pt}}$}};
\node at (4,4) {{\Huge \boldmath $D$}};
\node at (4,-4) {{\Huge \boldmath $\bar {D \rule{0pt}{18pt}}$}};
\filldraw[pattern color=gray!90, pattern=vertical lines] (3.5,1) to[out=180, in=180] (4,2)
to[out=0,in=0] (4.5,.7)
to[out=180, in=45] (4,.4)
to[out=180,in=0] cycle
;
\draw[dashed] (-3.75,4.97) -- (4,2);
\draw[dashed] (-2,0) -- (4,.4);
\filldraw[pattern=gray horizontal lines] (4,-1) to[out=0,in=180] (4.5,-1.5)
to[out=0,in=0] (4.5,-2)
to[out=180,in=45] (4,-2.5)
to[out=225,in=180,looseness=1.5] cycle
;
\draw[dashed] (-2,0) -- (4,-1);
\draw[dashed] (-3.8,-4.97) -- (3.85,-2.6);
\draw[thick, ->] (-1.5,1.5) -- (1.5,1.5) node[pos=.5,above] {\LARGE $f$};
\draw[thick, ->] (-1.5,-2) -- (1.5,-2) node[pos=.5,below] {\LARGE $f$};
\end{tikzpicture}
\caption{A schematic illustration of a reduction between two classification problems.}
\end{figure}
\end{document}
答案2
我实际上不知道这是否有效,因为我不知道如何在没有 Acrobat PRO 的情况下检查各个元素的颜色,除了仔细阅读未压缩的 PDF 文件并希望我能正确理解 PDF 规范。
未压缩的 PDF 文件似乎在正确的位置(例如,0 0 0 1
对于black
,1 0 0 0
对于cyan
等等)正确地产生了颜色。所以我猜它有点起作用¯\_(ツ)_/¯
无论如何,这都是一个黑客行为,因为 PGF 目前默认只生成 RGB 图案。在目前的形式下,它还可能破坏其他东西。但它可以成为适当解决方案的基础。
\pdfcompresslevel=0 % Only needed to open the PDF as text.
\documentclass[border=5]{standalone}
\usepackage[cmyk]{xcolor}
\usepackage{tikz}
\usetikzlibrary{patterns}
\makeatletter
% Patch \pgfutil@convertcolorspec to always use cmyk
% This is likely to have have side effects!
\def\pgfutil@convertcolorspec#1#2#3{\convertcolorspec{#1}{#2}{cmyk}}
% \pgf@set@fill@patternuncolored to use an extra argument
\def\pgf@set@fill@patternuncolored#1,#2,#3,#4\relax#5{%
\pgfsys@setpatternuncolored{\csname pgf@pattern@name@#5\endcsname}{#1}{#2}{#3}{#4}%
}
% Add the DeviceCMYK to the patterns resource.
\pgfutil@addpdfresource@colorspaces{ /pgfpcmyk [/Pattern /DeviceCMYK] }
% Set the uncolored pattern.
\def\pgfsys@setpatternuncolored#1#2#3#4#5{%
\pgfsysprotocol@literal{/pgfpcmyk cs #2 #3 #4 #5/pgfpat#1\space scn}%
}
\makeatother
\begin{document}
\tikz
\draw [pattern color=black, pattern=horizontal lines]
(0,0) rectangle (1,1);
\end{document}