3

I have a "fading line" from white to grey in my header. I wanted to add a page with a different background colour, and therefore fade from this colour instead of white. The problem is that the start of the gradient doesn't match the colour of the page... Any ideas? Complete code below.

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

3 Answers3

2

The problem is that you are defining the new background color using CMYK model and using RGB model for the gradient.

Use

\definecolor{bgsummary}{rgb}{0.8,1,0.9}

enter image description here

Sigur
  • 37,330
  • Brilliant! Thanks! Is it possible to do it the other way around? I tried changing the grey colours to cmyk, but it wasn't enough... Is tikz RGB based, or can I use cmyk instead? – Lars Nersveen May 02 '15 at 11:46
  • It is better to don't mix colour models. You can convert between them. http://web.forret.com/tools/color.asp Since it is not a good idea to print a pdf file with coloured BG, I suggest you to use RGB model, it works well for screens. – Sigur May 02 '15 at 11:48
  • This is for a book, so it will be printed. The coloured bg is only for a summary page at the end of each chapter. All the content will therefore be printed using cmyk. – Lars Nersveen May 02 '15 at 12:01
  • So read the Tikz user guide and xcolor also to use cmyk as a model. – Sigur May 02 '15 at 12:06
2

If you use the xcolor package option cmyk the xcolor package will convert all colors to the cmyk model. Nevertheless shade will use rgb colors. See the following example:

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

Result with option rgb

enter image description here

Result with option cmyk

enter image description here

But you can load the fadings library and use 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}

Note that I have used 5.98 instead 4.98 as width of the headrule rectangle and that the summary page also gets the pagestyle fancy.

enter image description here

esdd
  • 85,675
1

Update

tikz now supports CMYK shadings since version 3.1.3. Just load xcolor with the cmyk option before loading tikz.


The other answers explain why you get this problem well.

There is a new solution to this problem using the pgf-cmykshadings package which supports CMYK shadings in pgf. Change the start of your document to:

\documentclass[11pt, titlepage, openright]{book}
\usepackage[cmyk]{xcolor}% always use CMYK
\usepackage{pgf-cmykshadings}% use CMYK in PGF shadings

You need to load pgf-cmykshadings before tikz to ensure you get CMYK shadings everywhere. I'd also load xcolor with the cmyk option in your case and maybe define your grey colours in cmyk too.

\definecolor{grey}{cmyk}{0,0,0,0.4}
\definecolor{darkgrey}{cmyk}{0,0,0,0.6}

Now the colours will match and you'll get a document in CMYK suitable for printing.

enter image description here

David Purton
  • 25,884