我的页眉中有一条从白色到灰色的“渐变线”。我想添加一个具有不同背景颜色的页面,因此渐变的颜色从该颜色而不是白色开始。问题是渐变的起点与页面的颜色不匹配...有什么想法吗?完整代码如下。
\documentclass[11pt, titlepage, openright]{book}
\usepackage[textwidth=13cm, left=2.5cm, bottom=2cm, top=2.5cm, paperwidth=20cm, paperheight=27cm, layoutwidth=19cm, layoutheight=26cm, layouthoffset=0.5cm, layoutvoffset=0.5cm, showcrop, asymmetric]{geometry}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{lipsum}
\definecolor{bgsummary}{cmyk}{0.2,0,0.1,0}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead{}
\fancyfoot{}
\definecolor{grey}{rgb}{0.6,0.6,0.6}
\definecolor{darkgrey}{rgb}{0.4,0.4,0.4}
\setlength{\headheight}{24pt}
\fancyhead[RO]{\sffamily\bfseries\textcolor{grey}\leftmark\hspace{0.3cm}\sffamily\textcolor{darkgrey}\thepage}
\fancyhead[LE]{\sffamily\bfseries\textcolor{darkgrey}\thepage\hspace{0.3cm}\sffamily\textcolor{grey}\leftmark}
\renewcommand{\headrulewidth}{0.6pt}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\headrule}{%
\vskip-\baselineskip\vskip4pt
\ifodd\count0\hfill\begin{tikzpicture}
\shade[left color=white, right color=black, dashed] (0,0) rectangle (4.98,0.01);
\end{tikzpicture}\else\begin{tikzpicture}
\shade[left color=black, right color=white, dashed] (0,0) rectangle (4.98,.01);
\end{tikzpicture}\fi}
\fancypagestyle{summary}{%
\fancyhead[RO]{\sffamily\bfseries\footnotesize\textcolor{grey}\leftmark\hspace{0.3cm}\sffamily\bfseries\normalsize\textcolor{darkgrey}\thepage}
\fancyhead[LE]{\sffamily\bfseries\textcolor{darkgrey}\thepage\hspace{0.3cm}\sffamily\bfseries\footnotesize\textcolor{grey}\leftmark}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\headrule}{%
\vskip-\baselineskip\vskip4pt
\ifodd\count0\hfill\begin{tikzpicture}
\shade[left color=bgsummary, right color=darkgrey, dashed] (0,0) rectangle (4.98,0.01);
\end{tikzpicture}\else\begin{tikzpicture}
\shade[left color=darkgrey, right color=bgsummary, dashed] (0,0) rectangle (4.98,0.01);
\end{tikzpicture}\fi}
}
\begin{document}
\chapter{Test chapter with a long title}
\lipsum
\newpage
\thispagestyle{summary}
\section{Summary}
\pagecolor{bgsummary}
\end{document}
答案1
如果您使用xcolor
包选项,cmyk
包xcolor
会将所有颜色转换为cmyk
模型。尽管如此,shade
仍将使用rgb
颜色。请参阅以下示例:
\documentclass[margin=10pt,
rgb, % this option is passed to xcolor
%cmyk % this option is passed to xcolor
]{standalone}
\usepackage{tikz}
\definecolor{bgsummary}{cmyk}{0.2,0,0.1,0}
\pagecolor{bgsummary}
\begin{document}
\tikz\draw[fill=bgsummary](0,0)rectangle(1,1);
\tikz\draw[shade,left color=bgsummary,right color=bgsummary](0,0)rectangle(1,1);
\end{document}
带选项的结果rgb
带选项的结果cmyk
但您可以加载该fadings
库并使用path fading
。
\documentclass[11pt, titlepage, openright,
cmyk% this option is passed to xcolor
]{book}
\usepackage[textwidth=13cm, left=2.5cm, bottom=2cm, top=2.5cm,
paperwidth=20cm, paperheight=27cm,
layoutwidth=19cm, layoutheight=26cm,
layouthoffset=0.5cm, layoutvoffset=0.5cm,
showcrop, asymmetric]{geometry}
\usepackage{fancyhdr}
\usepackage{tikz}
\usetikzlibrary{fadings}
\definecolor{bgsummary}{cmyk}{0.2,0,0.1,0}
\definecolor{grey}{rgb}{0.6,0.6,0.6}
\definecolor{darkgrey}{rgb}{0.4,0.4,0.4}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhead{}
\fancyfoot{}
\setlength{\headheight}{24pt}
\fancyhead[RO]{\sffamily\bfseries\textcolor{grey}%
\leftmark\hspace{0.3cm}\sffamily\textcolor{darkgrey}\thepage}
\fancyhead[LE]{\sffamily\bfseries\textcolor{darkgrey}%
\thepage\hspace{0.3cm}\sffamily\textcolor{grey}\leftmark}
\renewcommand{\headrulewidth}{0.6pt}
\renewcommand{\footrulewidth}{0pt}
\renewcommand{\headrule}{%
\vskip-\baselineskip\vskip4pt
\ifodd\count0\hfill\begin{tikzpicture}
\fill[black,path fading=west] (0,0) rectangle (5.98,0.01);
\end{tikzpicture}\else\begin{tikzpicture}
\fill[black,path fading=east] (0,0) rectangle (5.98,.01);
\end{tikzpicture}\fi}
\usepackage{lipsum}% dummy text
\begin{document}
\chapter{Test chapter with a long title}
\lipsum
\clearpage
\pagecolor{bgsummary}
\section{Summary}
\end{document}
请注意,我已使用5.98
作为4.98
标题规则矩形的宽度,并且摘要页面也获得了页面样式fancy
。
答案2
问题在于您正在使用 CMYK 模型定义新的背景颜色并使用 RGB 模型进行渐变。
使用
\definecolor{bgsummary}{rgb}{0.8,1,0.9}
答案3
更新
tikz
自 3.1.3 版起支持 CMYK 阴影。只需在加载前xcolor
使用该选项加载即可。cmyk
tikz
其他答案很好地解释了你为什么会遇到这个问题。
有一个新的解决方案,使用pgf-cmykshadings
支持 CMYK 阴影的包来解决此问题pgf
。将文档的开头更改为:
\documentclass[11pt, titlepage, openright]{book}
\usepackage[cmyk]{xcolor}% always use CMYK
\usepackage{pgf-cmykshadings}% use CMYK in PGF shadings
您需要pgf-cmykshadings
先加载tikz
以确保到处都有 CMYK 阴影。我还会xcolor
根据cmyk
您的情况加载选项,并可能定义您的灰色cmyk
。
\definecolor{grey}{cmyk}{0,0,0,0.4}
\definecolor{darkgrey}{cmyk}{0,0,0,0.6}
现在颜色将匹配,您将获得适合打印的 CMYK 文档。