7

Similar questions have been asked before but none of them seem to answer my question. I want a \documentclass{letter} with an image in the header of the first page only. I can achieve this with fancyhdr, but this causes the top margin to be huge on all subsequent pages. How can I get fancyhdr to affect only the first page? Or, if there's another way to do it without fancyhdr, that would be fine too.

MWE below. I tried to define a "plain" style to apply to subsequent pages, but that has no effect unless I uncomment the \thispagestyle{plain}, which fixes the margin on the second page but removes the image from the first page!

\documentclass[12pt]{letter}
\usepackage[margin=1.3in]{geometry}
\pagenumbering{gobble}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{lipsum}

\fancypagestyle{empty}{\fancyhf{}\fancyhead[L]{\vspace{65pt}\includegraphics[height=1in, keepaspectratio=true]{example-image}}}
\renewcommand{\headrulewidth}{0pt}

\fancypagestyle{plain}{}
\pagestyle{plain}

\address{\hfill 123 Fake St \\ \hfill Faketown \\ \hfill Fakelandia 54321}

\date{} 
\begin{document}

\begin{letter}{321 Ekaf St \\ Nwotekaf \\ Aidnalekaf 12345}
\opening{Dear You Guys:}

%\thispagestyle{plain}

\lipsum[1-6]

\closing{Yours sincerely,\\
\fromsig{\includegraphics[scale=0.2]{example-image}} \\
\fromname{John Hancock}
}

\end{letter}
\end{document}

enter image description here

enter image description here

6

You could use package scrlayer. It redefines empty as layer page style. So you can declare a new layer and add this to page style empty:

\usepackage{scrlayer}
\DeclareNewLayer[
  foreground,
  textarea,
  contents={\includegraphics[height=1in, keepaspectratio=true]{kitty}}
]{letterimage}
\AddLayersToPageStyle{empty}{letterimage}

enter image description here

Code:

\documentclass[12pt]{letter}
\usepackage[margin=1.3in]{geometry}
\pagenumbering{gobble}
\usepackage
  [demo]% only for the example because I do not have the pictures
  {graphicx}
\usepackage{lipsum}% only for dummy text

\usepackage{scrlayer}
\DeclareNewLayer[
  foreground,
  textarea,
  contents={\includegraphics[height=1in, keepaspectratio=true]{kitty}}
]{letterimage}
\AddLayersToPageStyle{empty}{letterimage}

\address{\hfill 123 Fake St \\ \hfill Faketown \\ \hfill Fakelandia 54321}
\date{} 
\begin{document}
\begin{letter}{321 Ekaf St \\ Nwotekaf \\ Aidnalekaf 12345}
\opening{Dear You Guys:}
\lipsum[1-6]
\closing{Yours sincerely,\\
\fromsig{\includegraphics[scale=.2]{signature}} \\
\fromname{John Hancock}
}
\end{letter}
\end{document}

If there are other pages using page style empty too, you can define a new page style for the first page of the letter:

\usepackage{scrlayer}
\DeclareNewLayer[
  foreground,
  textarea,
  contents={\includegraphics[height=1in, keepaspectratio=true]{kitty}}
]{letterimage}
\DeclareNewPageStyleByLayers{letterfirstpage}{letterimage}

Then you can patch \opening to replace \thispagestyle{empty}:

\usepackage{xpatch}
\xpatchcmd\opening
  {\thispagestyle{empty}}{\thispagestyle{letterfirstpage}}
  {}{\PatchFailed}

Now it is possible to use page style empty for the other pages:

Code:

\documentclass[12pt]{letter}
\usepackage[margin=1.3in]{geometry}
%\pagenumbering{gobble}% <- removed
\usepackage
  [demo]% only for the example because I do not have the pictures
  {graphicx}
\usepackage{lipsum}% only for dummy text

\usepackage{scrlayer}
\DeclareNewLayer[
  foreground,
  textarea,
  contents={\includegraphics[height=1in, keepaspectratio=true]{kitty}}
]{letterimage}
\DeclareNewPageStyleByLayers{letterfirstpage}{letterimage}
\usepackage{xpatch}
\xpatchcmd\opening
  {\thispagestyle{empty}}{\thispagestyle{letterfirstpage}}
  {}{\PatchFailed}

\pagestyle{empty}% empty page style for the other pages

\address{\hfill 123 Fake St \\ \hfill Faketown \\ \hfill Fakelandia 54321}
\date{} 
\begin{document}
\begin{letter}{321 Ekaf St \\ Nwotekaf \\ Aidnalekaf 12345}
\opening{Dear You Guys:}
\lipsum[1-6]
\closing{Yours sincerely,\\
\fromsig{\includegraphics[scale=.2]{signature}} \\
\fromname{John Hancock}
}
\end{letter}
\end{document}

The result is the same as above.

4

A simple \raisebox with optional [0pt][0pt] to fool LaTeX will do:

\documentclass[12pt]{letter}
\usepackage[margin=1.3in]{geometry}
\pagenumbering{gobble}
\usepackage[demo]{graphicx}
\usepackage{fancyhdr}
\usepackage{lipsum}

\fancypagestyle{empty}{\fancyhf{}\fancyhead[L]{\raisebox{-\dimexpr 50pt+1in}[0pt][0pt]{\includegraphics[height=1in, keepaspectratio=true]{example-imagea}}}}
\renewcommand{\headrulewidth}{0pt}

\fancypagestyle{plain}{}
\pagestyle{plain}

\address{\hfill 123 Fake St \\ \hfill Faketown \\ \hfill Fakelandia 54321}

\date{}
\begin{document}
\thispagestyle{empty}
\begin{letter}{321 Ekaf St \\ Nwotekaf \\ Aidnalekaf 12345}
\opening{Dear You Guys:}

\pagestyle{plain}

\lipsum[1-6]

\closing{Yours sincerely,\\
\fromsig{\includegraphics[scale=0.2]{signature}} \\
\fromname{John Hancock}
}

\end{letter}
\end{document} 

enter image description here

4

You could use a highly configurable letter class like scrlttr2:

\documentclass[12pt,fromalign=right,fromlogo,backaddress=false]{scrlttr2}
\usepackage[margin=1.3in]{geometry}
\pagestyle{empty}
\usepackage{graphicx}
\usepackage{lipsum}

\setkomavar{fromname}{John Hancock}
\setkomavar{fromlogo}{\includegraphics[scale=0.2]{example-image-a}}
\setkomavar{fromaddress}{123 Fake St \\ Faketown \\ Fakelandia 54321}
\setkomavar{date}{}
\setkomavar{signature}{\includegraphics[height=2\baselineskip,width=4cm]{example-image}\\
 \usekomavar{fromname}
}
\let\raggedsignature\raggedright
\makeatletter
\@setplength{firstheadwidth}{\textwidth}
\@setplength{firstheadvpos}{\dimexpr\topmargin+1in\relax}
\@addtoplength{toaddrvpos}{-2cm}
\@setplength{toaddrhpos}{\dimexpr\oddsidemargin+1in\relax}
\@addtoplength{refvpos}{-4cm}
\@setplength{sigbeforevskip}{0pt}
\@setplength{sigindent}{.5\textwidth}
\makeatother

\begin{document}

\begin{letter}{321 Ekaf St \\ Nwotekaf \\ Aidnalekaf 12345}
\opening{Dear You Guys:}

\lipsum[1-6]

\closing{Yours sincerely}

\end{letter}
\end{document}

enter image description here

Instead of scrlttr2 you can also use a standard class or a KOMA-Script class and package scrletter. The package provides almost the same functionality like the class.

0

Try this simpler option. In the first page, set \thispagestyle{fancy}, with the changes in the header that you want. Then, at the beginning of the second page, reset \pagestyle{fancy} with the settings for the header without the figure and the usual settings for the remaining pages. That is, include \pagestyle{fancy} together with \rhead{}, \rfoot{\thepage} etc.

  • This won't prevent fancyhdr to increase \headheight as a result of the large head of the first page, because \@fancyvbox uses a \global\setlength. – Schweinebacke May 9 '17 at 13:48

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.