1

This question is building from the elegant solution posted here.

I wanted to be able to control the size (scale) of the even and odd images in the header also.

Is something like this possible (?):

\headimages{example-image}[scale = 0.5]{example-image-a}[scale = 0.7]?

Thanks!

Here is the original solution:

\documentclass[11pt,a4paper]{book}
\usepackage{calc}
\usepackage[left=1.5cm, right=1.5cm, bindingoffset=1.5cm, headheight=120pt, top={120pt+10mm}]{geometry}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{fourier}
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}

\definecolor{gmitblue}{RGB}{93,138,168}
\definecolor{line}{RGB}{70,160,216}

\usetikzlibrary{calc}
\renewcommand{\headrulewidth}{0pt}
\newcommand\hdheight{1in}
\newcommand\ftheight{.5in}

\newsavebox\headimageodd
\newsavebox\headimageeven
\newcommand*{\headimages}[3][]{%
  % #1 - optional argument added to the optional argument of both \includegraphics
  % #2 - name of even/left side page head image
  % #3 - name of odd/right side page head image
  \savebox{\headimageeven}{%
    \includegraphics[height=120pt,#1]{#2}%
  }%
  \savebox{\headimageodd}{%
    \includegraphics[height=120pt,#1]{#3}%
  }%
}
\headimages{example-image-b}{example-image-a}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[O]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (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);
    \ifnum\value{chapter}=0
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries]  at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \else
      \node[anchor=south west, text width=2cm, text=white, font=\fontsize{2cm}{1.5cm}\selectfont\bfseries] (oddpagenum) at ($(current page.north west)+(.5\hdheight,-\hdheight)$) {\thechapter};
      \node[anchor=south west, text width=11.5cm, text=white, font=\fontsize{.5cm}{1.5cm}\selectfont\bfseries] (chapter) at (oddpagenum.south east) {\quad TOPIC TO BE DISCUSSED};
    \fi
    \node[anchor=north east, inner xsep=5mm] at (current page.north east) {\usebox\headimageodd};
  \end{tikzpicture}%
}
\fancyhead[E]{%
  \begin{tikzpicture}[overlay, remember picture]%
    \fill[gmitblue] (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 east, text width=7cm, text=white, font=\fontsize{.7cm}{1.5cm}\selectfont\bfseries] (evenpagenum) at ($(current page.north east)+(-.5\hdheight,-\hdheight)$) {\raggedleft\rightmark};
    \node[anchor=north west, inner xsep=5mm] at (current page.north west) {\usebox\headimageeven};
  \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\bfseries, 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\bfseries, minimum size=.5in] at (current page.south east) {\thepage};
  \end{tikzpicture}%
}

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

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{}{0pt}{\Huge}
\titlespacing*{\chapter} {0pt}{20pt}{40pt}

\begin{document}
\maketitle
\tableofcontents
\listoffigures

\chapter{Problem 1}
\headimages{example-image-c}{example-image}
\section{Problem 1}
\lipsum[1]

\section{Solution 1}
\lipsum
\lipsum

\chapter{Problem 2}
\headimages{example-image-a}{example-image-b}
\section{Problem 2}
\lipsum[1]


\end{document}
  • Use \NewDocumentCommand provided by xparse. So you can define \headimages very simple: \NewDocumentCommand\headimages{oomom}{--code--} – Marco Daniel Jan 30 '17 at 21:10
  • @MarcoDaniel Thanks for your comment! I humbly request further documentation of your implementation. – Joe Jan 30 '17 at 21:34
  • @MarcoDaniel, can you explain what is the {oomon}? Thanks. – Joe Jan 31 '17 at 17:45
  • See texdoc xparse: o represents an optional argument // m represents a mandatory argument. -- Maybe the following question will help: tex.stackexchange.com/questions/345343/… – Marco Daniel Jan 31 '17 at 19:41
  • @MarcoDaniel, I tried this command: \NewDocumentCommand\headimages{oomom}{% \savebox{\headimageeven}{% \includegraphics[height=120pt,#1]{#2}% }% \savebox{\headimageodd}{% \includegraphics[height=120pt,#1]{#3}% }% } with the usage: \headimages[scale=.5][example-image-a]{example-image-b}[scale=2], but it does not work. Can you direct me further? Thanks! – Joe Jan 31 '17 at 21:31
1

Without any modification of the original code I suggest using the advantages of xparse to define the command \headings

\usepackage{xparse}
\NewDocumentCommand{\headimages}{m O{height=120pt} m O{height=120pt}}{%
  % #1 - mandotory argument: first image
  % #2 - optional argument for first image
  % #3 - mandotory argument: second image
  % #4 - optional argument for second image
  \savebox{\headimageeven}{%
    \includegraphics[#2]{#1}%
  }%
  \savebox{\headimageodd}{%
    \includegraphics[#4]{#3}%
  }%
}

Usage:

\headimages{e{<first image name>}[<options first image>]{<second image name>}[<options second image>]
  • Thanks for your input. I tried the usage: \headimages{example-image}[scale=.5]{example-image-b}[scale=.1], but the images do not scale? Do you think that I am implemting your solution incorrectly? – Joe Feb 1 '17 at 20:28
  • 1
    @Joe: scale has no effect. The definition of height has a higher priority. Try \headimages{example-image}[scale=.5]{example-image-b}[height=10pt] -- BTW: I changed the implementation of the default value. – Marco Daniel Feb 1 '17 at 20:45

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.