8

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}
Bla bla bla. In this page the pagestyle would be empty.
\newpage
\begin{tikzpicture}[remember picture,overlay]
    \fill[lightgray] (-90pt,1cm) rectangle (0pt,2.5cm); %riquadro ad inizio pagina
    \draw[gray] (-90pt,1cm)--(470pt,1cm);   %linea sotto riquadro ad inizio pagina
    \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] (380pt,1cm) rectangle (470pt,2.5cm);   %riquadro (destro) ad inizio pagina
    \draw[gray] (-90pt,1cm)--(470pt,1cm);   %linea sotto riquadro ad inizio pagina
    \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.

5
  • 2
    the background package sounds like it would be pretty useful here
    – cmhughes
    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
    – Martino
    Jun 18 '13 at 16:07
  • have you tried to solve it with scrpage2
    – Micha
    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
5

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}

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

\fancyhead[LE]{%
\begin{tikzpicture}[overlay]
\fill[lightgray] (0,-4pt) rectangle (\mylen,\headheight+1in);
\node[anchor=east,font=\sffamily] at (\mylen,0) {\strut\chaptername~\thechapter};
\node[anchor=west,font=\slshape\sffamily] at (\mylen,0) {\strut\leftmark};
\end{tikzpicture}%
}

\fancyhead[RE]{%
\begin{tikzpicture}[overlay]
\fill[lightgray] (0,-4pt) rectangle (\mylen,\headheight+1in);
\node[anchor=east,font=\slshape\sffamily] at (-90pt,0) {\strut Author};
\end{tikzpicture}%
}

\fancyhead[RO]{%
\begin{tikzpicture}[overlay]
\fill[lightgray] (-\mylen,-4pt) rectangle (0,\headheight+1in);
\node[anchor=east,font=\slshape\sffamily] at (-\mylen,0) {\strut\leftmark};
\node[anchor=west,font=\sffamily] at (-\mylen,0) {\strut\chaptername~\thechapter};
\end{tikzpicture}%
}

\fancyhead[LO]{%
\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}

enter image description here

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

enter image description here

the header for an even page:

enter image description here

finally, a footer:

enter image description here

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.