精美的页眉和页脚

精美的页眉和页脚

我想为我的 Latex PDF 中的所有页面创建页眉和页脚,它们应该如下所示:

标头

1)一英寸厚;背景颜色:蓝色;左侧:文档标题;右侧:Logo(logo.jpg;文件放在DOCUMENT文件夹中);

页脚

1) 半英寸厚;背景颜色:蓝色;左侧:页码;中间:章节标题;右侧:日期;仅偶数页。

2)半英寸厚;背景颜色:蓝色;左侧:日期;中间:章节标题;右侧:页码;仅限奇数页。

\documentclass[twoside,a4paper]{report}
\usepackage{fancyhdr, graphicx}
\usepackage{makeidx}
\usepackage{ifthen}
\usepackage{framed}
\usepackage[usenames, dvipsnames]{color}
\usepackage{environ}
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{DejaVuSansCondensed}
\makeindex
\begin{document}

\maketitle
\newpage
%-- header here
%-- even footer here

\newpage
%-- header here
%-- odd footer here

\end{document}

答案1

使用您已加载的 TikZ 可以轻松完成此操作。我没有设置任何边距,但如果您使用的是twoside,也许您需要适当的边距来进行绑定。如果是这样,请告诉我,我会修复该示例。

输出

在此处输入图片描述

在此处输入图片描述

代码

\documentclass[twoside]{report}
\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{gmitblue}{RGB}{93,138,168}

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

\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{%
\begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (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) {\includegraphics[scale=.2]{example-image-a}};
      %node[minimum width=\x2-\x1, minimum height=2cm, draw, rectangle, fill=blue!20, anchor=north west, align=left, text width=\x2-\x1] at ($(current page.north west)$) {\Large\bfseries \quad #1};
\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[1-9]

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

相关内容