[Tex/LaTex] Fancy header and footer including images with tikz

graphicsheader-footersectioningtikz-pgf

Consider the following code:

% DOCUMENT TYPE
\documentclass[12pt,a4paper]{article}

% PACKAGES
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[margin=10pt,font=footnotesize,labelfont=bf]{caption}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{fancybox}
\usepackage{amsmath}
\usepackage{array}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{floatrow}
\usepackage{subfigure}
\usepackage{enumitem}
\usepackage{appendix}
\usepackage{listings}
\usepackage{multicol}
\usepackage{sistyle}
\usepackage{color}
\usepackage{tikz}
\usepackage{lmodern}
\usepackage{multicol}
\usepackage{seqsplit}
\usepackage[listings,skins,theorems]{tcolorbox}
\usepackage{libertine}
\usepackage[export]{adjustbox}
\usepackage[normalem]{ulem}
\usepackage[top=1.25in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}
\usepackage{calc}
\usetikzlibrary{calc}
\usepackage{hyperref}

% PRESENTATION
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhead[LO]{\rightmark}   
\fancyhead[RE]{\leftmark}
\fancyfoot[CE,CO]{\thepage}
\hypersetup{colorlinks, citecolor=blue, filecolor=blue, linkcolor=blue, urlcolor=blue}

% DOCUMENT BEGINNING
\title{Title}
\author{Author}
\date{\today}
\begin{document}
\maketitle
\tableofcontents
\newpage
\section{First section}
\subsection{First subsection}
\lipsum
\lipsum
\subsection{Second subsection}
\lipsum
\lipsum
\section{Second section}
\subsection{First subsection}
\lipsum
\lipsum
\subsection{Second subsection}
\lipsum
\lipsum
\section{Third section}
\subsection{First subsection}
\lipsum
\lipsum
\subsection{Second subsection}
\lipsum
\lipsum

\end{document}
% DOCUMENT END

Which produces the following output:

enter image description here

My goal is to obtain the following result, using the image available here, probably using tikz and/or fancyhdr to design the layout (but any other package is welcome):

enter image description here

With:

  • The top of the image imported as a 2cm header, with a 0.2cm blue line at the bottom of it
  • With the current section on the even pages and the document title on the odd pages in big blank capital letters, left aligned
  • The bottom of the image imported as a 0.5cm footer, with a 0.2cm blue line at the top of it
  • With the current page number in blank letters, centered
  • Except on the first title page

I have no knowledge of tikz and I want to learn how to do that.

How to do such a thing?

Best Answer

Here is a suggestion using scrlayer to define a new pagestyle.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{tikz}% loads also graphicx, xcolor
\usepackage{lmodern}
\usepackage[top=1.25in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}

\usepackage{scrlayer}[2015/02/07]
\newkomafont{myheadfoot}{\color{white}\bfseries\sffamily}
\newkomafont{myhead}{\Huge}
\newkomafont{mypagenumber}{\normalsize}
\newkomafont{mysepline}{\color{blue}}

\newcommand\headimageheight{2cm}
\newcommand\footimageheight{.5cm}
\newcommand\seplineheight{.2cm}
\newcommand\headtexthoffset{1cm}

\renewcommand\sectionmark[1]{\markright{#1}}
\newcommand\titleinhead{}
\newcommand\mytitle[1]{\title{#1}\renewcommand\titleinhead{#1}}

\newsavebox\headimage
\sbox\headimage{%
  \tikz{
    \clip(0,0)rectangle(\paperwidth,-\headimageheight);
    \node[inner sep=0pt,outer sep=0pt,anchor=north west]{%
      \includegraphics[width=\paperwidth]{image}};
  }%
  \llap{\usekomafont{mysepline}\rule[-\seplineheight]{\paperwidth}{\seplineheight}}%
}
\newsavebox\footimage
\sbox\footimage{%
  \tikz{
    \clip(0,0)rectangle(\paperwidth,\footimageheight);
    \node[inner sep=0pt,outer sep=0pt,anchor=south west]{%
      \includegraphics[width=\paperwidth]{image}};
  }%
  \llap{\usekomafont{mysepline}\rule[\footimageheight]{\paperwidth}{\seplineheight}}%
}

\DeclareNewLayer[
  background,
  area={0pt}{0pt}{\paperwidth}{\headimageheight},
  contents={%
    \parbox[c][\layerheight]{\layerwidth}{%
      \vspace*{\stretch{2}}
      \hspace*{\headtexthoffset}%
      \usekomafont{myheadfoot}\usekomafont{myhead}\smash{\MakeUppercase{%
        \ifodd\value{page}\titleinhead\else\rightmark\fi%
      }}%
      \vspace*{\stretch{1}}}%
    %}%
  }
]{headtext}
\DeclareNewLayer[
  clone=headtext,
  addheight=\seplineheight,
  contents={\usebox\headimage}
]{headimage}
\DeclareNewLayer[
  background,
  align=b,
  area={0pt}{\paperheight}{\paperwidth}{\footimageheight},
  contents={%
    \parbox[c][\layerheight][c]{\layerwidth}{\centering\usekomafont{myheadfoot}\usekomafont{mypagenumber}\thepage}%
  }
]{foottext}
\DeclareNewLayer[
  clone=foottext,
  addheight=\seplineheight,
  contents={\parbox{\layerwidth}{\usebox\footimage}}
]{footimage}

\DeclarePageStyleByLayers{headfootimage}{%
  headimage,headtext,%
  footimage,foottext%
}

\usepackage{lipsum}% dummy text
\begin{document}
\mytitle{Title}
\author{Author}
\maketitle
\tableofcontents

\clearpage
\pagestyle{headfootimage}
\section{First section}
\subsection{First subsection}
\lipsum
\lipsum
\subsection{Second subsection}
\lipsum
\lipsum
\section{Second section}
\subsection{First subsection}
\lipsum
\lipsum
\subsection{Second subsection}
\lipsum
\lipsum
\section{Third section}
\subsection{First subsection}
\lipsum
\lipsum
\subsection{Second subsection}
\lipsum
\lipsum
\end{document}

enter image description here

enter image description here

Related Question