# a tikzpicture on pages without chapter and index

I would get the result of the output below

\documentclass[11pt, a4paper]{book}
\usepackage{geometry}
\geometry{%
papersize={19.7cm,27cm},
centering,
textwidth=380pt,
textheight=650pt}

\usepackage{fancyhdr}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\usepackage{tikz}
\parindent=0pt
\pagestyle{empty}

\begin{document}
\chapter{Title of chapter}
\section{and section}
\newpage
\begin{tikzpicture}[remember picture,overlay]
\fill[lightgray] ({\textwidth/2-30pt},-23.45cm) rectangle ({\textwidth/2+30pt},-24.45cm);   %riquadro per la pagina
\draw[gray] (-90pt,-23.45cm)--(470pt,-23.45cm); %linea di fondo pagina
\node at (0,1.25cm) [left]{\sffamily\chaptername\ \thechapter};
\node at (0,1.25cm) [right]{\slshape\sffamily\leftmark};
\node at (380pt,1.25cm) [left] {\slshape\sffamily author};
\node at ({\textwidth/2},-23.9cm) {\bfseries\sffamily\thepage};
\end{tikzpicture}

Here there is some text (here the number of the page is even);

\newpage

\begin{tikzpicture}[remember picture,overlay]
\fill[lightgray] ({\textwidth/2-30pt},-23.45cm) rectangle ({\textwidth/2+30pt},-24.45cm);   %riquadro per la pagina
\draw[gray] (-90pt,-23.45cm)--(470pt,-23.45cm); %linea di fondo-pagina
\node at (380pt,1.25cm) [right]{\sffamily\chaptername\ \thechapter};
\node at (380pt,1.25cm) [left]{\slshape\sffamily\leftmark};
\node at (0pt,1.25cm) [right]{\slshape\sffamily\rightmark};
\node at ({\textwidth/2},-23.95cm) {\bfseries\sffamily\thepage};
\end{tikzpicture}

And here there is some text too (here the number of the page is odd).
\end{document}


but on every page of the document. I already notice that there is a discussion about my question, but there I cannot obtain sufficient information on the use of everypage package, or something that put me on the right track to solve this problem.

• the background package sounds like it would be pretty useful here Jun 18 '13 at 15:53
• Are you sure this should go on every page, even for special pages such as the first page of a chapter, or pages that are usually left blank? Jun 18 '13 at 16:00
• No: I mean to put the two pictures above on every page that does not contain index or chapters. I will take a look to the background package documentation in order to realise how avoid these special pages Jun 18 '13 at 16:07
• have you tried to solve it with scrpage2 Jun 18 '13 at 16:50
• @Lorenzo I don't think background is the more useful option here; see the reasons in my answer below. By the way, I would suggest you to change the title of your question since, in its present form, it is misleading (you don't really want the formatting on every page). Jun 18 '13 at 23:05

Here's one possibility, using the fancyhdr package to define a page style with the specifications required:

\documentclass[11pt, a4paper]{book}
\usepackage{geometry}
\geometry{%
papersize={19.7cm,27cm},
centering,
textwidth=380pt,
textheight=650pt}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{lipsum}% just to generate text automatically

\newlength\mylen
\setlength\mylen{\dimexpr1in+\hoffset+18pt\relax}

\fancyhfoffset[L,R]{\dimexpr1in+\hoffset+18pt\relax}
\fancyhf{}

\begin{tikzpicture}[overlay]
\node[anchor=east,font=\sffamily] at (\mylen,0) {\strut\chaptername~\thechapter};
\node[anchor=west,font=\slshape\sffamily] at (\mylen,0) {\strut\leftmark};
\end{tikzpicture}%
}

\begin{tikzpicture}[overlay]
\node[anchor=east,font=\slshape\sffamily] at (-90pt,0) {\strut Author};
\end{tikzpicture}%
}

\begin{tikzpicture}[overlay]
\node[anchor=east,font=\slshape\sffamily] at (-\mylen,0) {\strut\leftmark};
\node[anchor=west,font=\sffamily] at (-\mylen,0) {\strut\chaptername~\thechapter};
\end{tikzpicture}%
}

\begin{tikzpicture}[overlay]
\node[anchor=west,font=\slshape\sffamily] at (\mylen,0) {\rightmark};
\end{tikzpicture}%
}

\fancyfoot[C]{%
\begin{tikzpicture}[overlay]
\fill[lightgray] (-30pt,0) rectangle (30pt,-30pt);
\node[anchor=center,font=\bfseries\sffamily] at (0,-15pt) {\thepage};
\draw (-\textwidth,0) -- (\textwidth,0);
\end{tikzpicture}%
}

\parindent=0pt
\pagestyle{fancy}
\renewcommand\chaptermark[1]{\markboth{#1}{}}
\renewcommand\sectionmark[1]{\markright{\thesection\ #1}}

\begin{document}

\chapter{Title of chapter}
\section{Title of a Section}
\lipsum[1-30]

\end{document}


Some zoomed images: first, the header for an even page:

the header for an even page:

finally, a footer:

The use of the background package in this particular situation might not be the best approach since there are many pages (e.g., first page of each chapter, empty pages produced by internal \cleardoublepage commands) which shouldn't receive the style and doing this with background might require more effort than the present approach.