我正在写一封信,并使用fancyhdr
pdf 文件作为页眉。这是一封两页的信,我已指定页眉位于第一页和后续页面上。一切正常,直到我使用 添加回信地址address
。然后页眉从第一页消失。这是一个工作示例
\documentclass{letter}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{url}
\urlstyle{same}
\geometry{headheight = .6in}
\fancypagestyle{firstpage}{\fancyhf{}\fancyhead[L]{\includegraphics[height=0.5in, keepaspectratio=true]{header.pdf}}}
\fancypagestyle{plain}{\fancyhf{}\fancyhead[L]{\includegraphics[height=0.5in, keepaspectratio=true]{header.pdf}}}
\pagestyle{plain}
\address{Joe Smith \\ 100 Main Street. \\ Chicago, IL 60610}
\begin{document}%
\begin{letter}{Department \\ University of X\\ City, State Area Code}%
\opening{Dear Some Name,}
\lipsum{1:5}
\vspace{.5in}
\noindent Sincerely,
\vspace{.7in}
\noindent Joe Smith
\noindent Ph.D. Candidate
\noindent Department
\noindent University
\end{letter}%
\end{document}
答案1
letter.cls
包含以下几行(我只显示相关部分):
\newcommand*{\opening}[1]{\ifx\@empty\fromaddress
\thispagestyle{firstpage}%
{\raggedleft\@date\par}%
\else % home address
\thispagestyle{empty}%
{\raggedleft\begin{tabular}{l@{}}\ignorespaces
\fromaddress \\*[2\parskip]%
\@date \end{tabular}\par}%
\fi
这表明,当\address
使用 时,empty
将使用页面样式,而不是fitrspage
。在这种情况下,要plain
在第一页也使用 样式,您可以将\let
页面empty
样式简化为plain
:
\documentclass{letter}
\usepackage[demo]{graphicx}
\usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{url}
\urlstyle{same}
\geometry{headheight = .6in}
\fancypagestyle{plain}{\fancyhf{}\fancyhead[L]{\includegraphics[height=0.5in, keepaspectratio=true]{header.pdf}}}
\pagestyle{plain}
\address{Joe Smith \\ 100 Main Street. \\ Chicago, IL 60610}
\makeatletter
\let\ps@empty\ps@plain
\let\ps@firstpage\ps@plain
\makeatother
\begin{document}%
\begin{letter}{Department \\ University of X\\ City, State Area Code}%
\opening{Dear Some Name,}
\lipsum{1:5}
\vspace{.5in}
\noindent Sincerely,
\vspace{.7in}
\noindent Joe Smith
\noindent Ph.D. Candidate
\noindent Department
\noindent University
\end{letter}%
\end{document}
请注意,我还\let
\ps@firstpage
要这样做\ps@plain
(以节省代码)plain
无论是否\address
使用,所有页面都会收到该样式。
选项demo
只是graphicx
用黑色矩形替换实际图形;不是在实际文档中使用该选项。
答案2
您可以使用该background
包将徽标放置在文档的所有页面上。
\documentclass{letter}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{url}
\urlstyle{same}
\usepackage{background} % load the background package
\geometry{headheight = .6in}
% settings for the background package
\SetBgColor{black}
\SetBgScale{1}
\SetBgOpacity{1}
\SetBgAngle{0}
\SetBgContents{%
\begin{tikzpicture}[remember picture,overlay]
\node at (0,0.6\textheight) {\includegraphics[height=0.5in, keepaspectratio=true]{header.pdf}};
\end{tikzpicture}}
\pagestyle{empty}
\address{Joe Smith \\ 100 Main Street. \\ Chicago, IL 60610}
\begin{document}%
\begin{letter}{Department \\ University of X\\ City, State Area Code}%
\opening{Dear Some Name,}
\lipsum{1:5}
\vspace{.5in}
\noindent Sincerely,
\vspace{.7in}
\noindent Joe Smith
\noindent Ph.D. Candidate
\noindent Department
\noindent University
\end{letter}%
\end{document}