奇数页和偶数页上的精美页眉

奇数页和偶数页上的精美页眉

我需要一些帮助,使我的标题在奇数页上像这样显示:

在此处输入图片描述

偶数页如下:

在此处输入图片描述

这是我的最小代码:

\documentclass{book}
\usepackage[a4paper, left=1.5cm, right=1.5cm, bindingoffset=1.5cm]{geometry}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}

\definecolor{mybluei}{RGB}{199,234,253}
\definecolor{gmitblue}{RGB}{93,138,168}

\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[RE]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[mybluei] (current page.north west) rectangle ($(current page.north east)+(0,-1in)$);
    %\node[anchor=north west, text=white, font=\Large\scshape, minimum size=1in, inner xsep=5mm] at (current page.north west) {A reasonably long title};
    \node[anchor=north east, minimum size=1in, inner xsep=5mm] at ($(current page.north east)+(0,-.35in)$) 
    {Configuration Issues, System Design\hspace{.5cm} {\Huge\textbf{\textcolor{white}{\thechapter}}} \thepage};
\end{tikzpicture}
}
\fancyhead[LO]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[mybluei] (current page.north west) rectangle ($(current page.north east)+(0,-1in)$);
    %\node[anchor=north west, text=white, font=\Large\scshape, minimum size=1in, inner xsep=5mm] at (current page.north west) {A reasonably long title};
    \node[anchor=north west, minimum size=1in, inner xsep=5mm] at ($(current page.north west)+(0,-.35in)$)
    {\thepage {\Huge\textbf{\textcolor{white}{\thechapter}}} \hspace{.5cm} Configuration Issues, System Design};
\end{tikzpicture}
}
\fancyfoot[CE]{
    \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\Large, minimum size=.5in] at (current page.south west) {\thepage};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south east) {\today};
\end{tikzpicture}
}
\fancyfoot[CO]{
    \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (current page.south west) rectangle ($(current page.south east)+(0,.5in)$);
    \node[anchor=south west, text=white, font=\large, minimum size=.5in, inner xsep=5mm] at (current page.south west) {\today};
    \node[anchor=south, text=white, font=\large, minimum size=.5in] at (current page.south) {\leftmark};
    \node[anchor=south east, text=white, font=\Large, minimum size=.5in] at (current page.south east) {\thepage};
\end{tikzpicture}
}
\setlength{\headheight}{12pt}

\title{A reasonably long title}
\date{\today}
\author{The author}

\begin{document}
\maketitle
\chapter{first chapter}
\lipsum
\lipsum

\chapter{second chapter}
\lipsum[10-19]
\end{document} 

答案1

我不确定您是否也想要页脚,因为您的 OP 只显示了页眉。无论如何,这里有一个页眉的解决方案。您的尝试还不错,但例如,您没有考虑从页面侧面到页码、章节字母/编号和标题的距离。它们在两边应该是相同的,所以这里有一个小例子来说明这一点。

请注意,章节开始时不存在页眉和页脚。这是一个功能,但您可以更改它。

输出(各页)

章节
在此处输入图片描述

附录,偶数页
在此处输入图片描述

附录,奇数页
在此处输入图片描述

代码

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{geometry}
\usepackage{etoolbox,fancyhdr}

\usetikzlibrary{calc}

\definecolor{ultramarine}{RGB}{0,45,97}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{line}{RGB}{70,160,216}
\definecolor{fillh}{RGB}{225,233,251}

\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}

% uncomment this to see the distances are the same for evena nd odd pages.
%\tikzset{
%   every node/.style={draw}
%}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhf{}
\fancyhead[E]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[fillh] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[anchor=south west, font=\sffamily, text width=1cm] (evenpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\thepage};
    \node[anchor=south west, text width=1.5cm, text=white, font=\fontsize{2cm}{5.5cm}\selectfont] (chapter) at (evenpagenum.south east) {\thechapter};
    \node[anchor=south west] at (chapter.south east) {\leftmark};
\end{tikzpicture}
}%
\fancyhead[O]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[fillh] (current page.north west) rectangle ($(current page.north east)+(0,-\hdheight)$);
    \draw[line] ([yshift=-\hdheight]current page.north west) -- ([yshift=-\hdheight]current page.north east);
    \node[align=right, anchor=south east, font=\sffamily, text width=1cm] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\thepage};
    \node[align=right, anchor=south east, text width=1.5cm, text=white, font=\fontsize{2cm}{5.5cm}\selectfont] (chapter) at (evenpagenum.south west) {\thechapter};
    \node[align=right, anchor=south east] at (chapter.south west) {\leftmark};
\end{tikzpicture}
}
\fancyfoot[CE]{}
\fancyfoot[CO]{}
\setlength{\headheight}{12pt}

\begin{document}
\chapter{Problems}
\section{Problem 1}
\subsection{Problem 1}
\lipsum[1]
\subsection{Solution 1}
\lipsum[1-7]
\cleardoublepage

\appendix
\chapter{Appendix \thechapter}
\lipsum[1-20]

\end{document} 

相关内容