2

I want to include a small logo on particular pages in a large document, in the left hand side of the footer. The way to do this seems to be with fancyhdr's alternate-able styles.

I've gotten close to what I need, but I have 2 questions:

  1. The header style for the new logo pages is a direct copy of the IHA-fancy-style, but I have been setting the \lhead and \rhead on a chapter by chapter basis, and changing the text style. How can I change my current set up to apply the headers to the new pagestyle too?

  2. How should I be positioning my thispagestyle command, when an image is set to use a full page with the [p] parameter of the figure environment? It wants to apply to the page before or after it seems.

I hope this is clear enough, I'm struggling to explain what I'm trying to do in my own head, so I've no idea if this makes sense now!

Here's a MWE of what I have so far (note there is a specific filepath for the logo if people try to re-run the code).

You should see from this output PDF, that the page with the Logo on, is lacking the headers from the rest of the chapter/document, and isn't the page with the figure on.

\documentclass[a4paper, oneside, 11pt]{report}
\usepackage[left=4cm, right=2cm, top=1.5cm, bottom=2.5cm]{geometry}
\usepackage{lipsum}
\usepackage{graphicx} 
\usepackage{fancyhdr} 
\headsep 25pt
\headheight 20pt
\setlength{\topmargin}{0pt}
\setlength{\textheight}{670pt}

\fancypagestyle{IHA-fancy-style}{%
  \fancyhf{}
  \fancyhead[LE,RO]{\slshape \leftmark}
  \fancyfoot[LE,RO]{\thepage\ } % Custom footer
  \renewcommand{\headrulewidth}{0.4pt}% Line at the header visible
  \renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}

\fancypagestyle{augment}{%
  \fancyhf{}
  \fancyhead[LE,RO]{\slshape \leftmark}
  \fancyfoot[R]{\thepage\ } % Custom footer
  \fancyfoot[L]{\raisebox{-0.1cm}{\includegraphics[height=0.5cm, clip, trim={100 100 100 100}]{/path/to/mylogo.png}}
}
  \renewcommand{\headrulewidth}{0.4pt}% Line at the header visible
  \renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}

\begin{document}

\pagestyle{IHA-fancy-style}
\lhead{\textsf{Chapter 1}}
\rhead{\textsf{My First Chapter}}
\lipsum[1]
\newpage

\lipsum[2]


\thispagestyle{augment}
\begin{figure}[p]
\includegraphics[width=\textwidth, height=\textwidth, clip, trim={0 0 0 0}, draft]{/path/to/dummy/image.png}
\end{figure}
\newpage

\lipsum[3]
\end{document}

EDIT

The answer below does solve the problem for the minimal case I posted, but raised other issues when I brought it in to the full document.

2 issues mainly:

Firstly, I can typeset the document correctly once, but when it comes to a second time in order to populate the ToC, I'm now getting this error:

Undefined control sequence.              # Pointing to my document.toc file
\f@ncycolh ->\sffamily \myleftmark       # I added sffamily to the header in the answer below, but its a valid command
                                   \strut 

which points to this line in the ToC file, though I can't see that there's anything wrong with it specifically

\contentsline {subsection}{\numberline {3.3.2}Harvesting}{78}{subsection.3.3.2}

Secondly, when I include my Appendix Chapters (even with a \pagetyle{plain}) I get this error:

Use of \reserved@a doesn't match its definition.
\new@ifnextchar ...eseverd@d  = #1\def \reserved@a { 
                                                    #2}\def\reserved@vb {#3}\f...
 l.685  ...{Chapter \ref{appendix1}}
1

I modified \@chapter to automatically set \myleftmark to the chapter number and \myrightmark to the chapter name.

Note that report class is one sided (default), so there are no even pages.

\documentclass[a4paper, oneside, 11pt]{report}
\headsep 25pt
\headheight 20pt
\usepackage[left=4cm, right=2cm, top=1.5cm, bottom=2.5cm]{geometry}

\usepackage{lipsum}
\usepackage[draft]{graphicx} 
\usepackage{fancyhdr} 

\newcommand{\myleftmark}{}% reserve global name
\newcommand{\myrightmark}{}% reserve global name

\fancypagestyle{IHA-fancy-style}{%
  \fancyhf{}% remove default
  \fancyhead[L]{\myleftmark}%
  \fancyhead[R]{\myrightmark}%
  \fancyfoot[R]{\thepage\ } % Custom footer
  \renewcommand{\headrulewidth}{0.4pt}% Line at the header visible
  \renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}

\fancypagestyle{augment}{%
  \fancyhf{}% remove default
  \fancyhead[L]{\myleftmark}%
  \fancyhead[R]{\myrightmark}%
  \fancyfoot[R]{\thepage\ }% Custom footer
  \fancyfoot[L]{\raisebox{-0.1cm}{\includegraphics[height=0.5cm, clip, trim={100 100 100 100}]{/path/to/mylogo.png}}
}
  \renewcommand{\headrulewidth}{0.4pt}% Line at the header visible
  \renewcommand{\footrulewidth}{0.4pt}% Line at the footer visible
}
\pagestyle{IHA-fancy-style}

\usepackage{floatpag}
\floatpagestyle{augment}

\makeatletter
\let\@oldchapter=\@chapter
\def\@chapter[#1]#2{\@oldchapter[#1]{#2}%
  \xdef\myleftmark{Chapter~\thechapter}%
  \xdef\myrightmark{#2}%
}
\makeatother

\begin{document}

\chapter{My First Chapter}

\lipsum[1]
\newpage

\begin{figure}[p]
\includegraphics[width=\textwidth, height=\textwidth, clip, trim={0 0 0 0}, draft]{/path/to/dummy/image.png}
\end{figure}

\lipsum[2-16]

\end{document}
  • Perfect, this combined with @Werner's suggestion of floatpag seems to do the job nicely - spoke to soon. This causes some other issues with other document elements I wasn't anticipating. See edits above. – Joe Healey Jun 26 '18 at 9:53
  • For some reason it thinks I downvoted this answer, and that vote is now locked unless the answer is edited. If you make a superficial edit or something let me know and I'll try to amend the vote. – Joe Healey Jun 26 '18 at 14:39
  • 1
    Done. I've accidentally down voted before too. Very embarrassing! – John Kormylo Jun 27 '18 at 1:23

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.