之前有人问过类似的问题,但似乎都没有回答我的问题。我想要一个\documentclass{letter}
只在第一页的页眉中带有图像的 。我可以用 来实现这一点fancyhdr
,但这会导致所有后续页面的顶部边距都很大。我怎样才能fancyhdr
只影响第一页?或者,如果有另一种不使用 的方法fancyhdr
,那也可以。
下面的 MWE。我尝试定义一个“普通”样式以应用于后续页面,但除非我取消注释,否则这不会产生任何效果\thispagestyle{plain}
,这会修复第二页的边距但会从第一页中删除图像!
\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}
答案1
您可以使用包scrlayer
。它将empty
页面样式重新定义为层。因此,您可以声明一个新层并将其添加到页面样式中empty
:
\usepackage{scrlayer}
\DeclareNewLayer[
foreground,
textarea,
contents={\includegraphics[height=1in, keepaspectratio=true]{kitty}}
]{letterimage}
\AddLayersToPageStyle{empty}{letterimage}
代码:
\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}
如果其他页面empty
也使用页面样式,您可以为信件的第一页定义新的页面样式:
\usepackage{scrlayer}
\DeclareNewLayer[
foreground,
textarea,
contents={\includegraphics[height=1in, keepaspectratio=true]{kitty}}
]{letterimage}
\DeclareNewPageStyleByLayers{letterfirstpage}{letterimage}
然后你可以修补\opening
以替换\thispagestyle{empty}
:
\usepackage{xpatch}
\xpatchcmd\opening
{\thispagestyle{empty}}{\thispagestyle{letterfirstpage}}
{}{\PatchFailed}
现在可以将页面样式用于empty
其他页面:
代码:
\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}
结果和上面一样。
答案2
一个简单的\raisebox
带有可选项[0pt][0pt]
的欺骗 LaTeX 就可以做到:
\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}
答案3
您可以使用高度可配置的字母类,例如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}
您也scrlttr2
可以使用标准类或 KOMA-Script 类和包scrletter
。包提供的功能几乎与类相同。
答案4
尝试这个更简单的选项。在第一页中,设置\thispagestyle{fancy}
,并在页眉中更改您想要的设置。然后,在第二页的开头,\pagestyle{fancy}
使用不带图片的页眉设置和其余页面的常规设置进行重置。也就是说,包括\pagestyle{fancy}
,\rhead{}
等等\rfoot{\thepage}
。