不包含章节和索引的页面上的 tikzpicture

不包含章节和索引的页面上的 tikzpicture

我将获得以下输出结果

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

但在文档的每一页上。我已经注意到有关于我的问题的讨论,但是在那里我无法获得有关everypage包使用的足够信息,或者一些可以让我走上解决这个问题的正确轨道的东西。

答案1

这是一种可能性,使用fancyhdr包定义具有所需规格的页面样式:

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

在此处输入图片描述

一些放大的图像:首先,偶数页的页眉:

在此处输入图片描述

偶数页的页眉:

在此处输入图片描述

最后,页脚:

在此处输入图片描述

使用background在这种特殊情况下,包可能不是最好的方法,因为有许多页面(例如,每章的第一页,由内部\cleardoublepage命令生成的空白页)不应该接收样式,并且这样做background可能比现在的方法需要更多的努力。

相关内容