在LaTeX中,如何在Letter文档类中添加页眉/页脚?

22

在LaTeX中,如何使用Letter文档类创建一个具有自定义页眉和页脚的文档?

通常我会使用:

\usepackage{fancyhdr}

\pagestyle{fancy}
\lhead{\footnotesize \parbox{11cm}{Custom left-head-note} }
\lfoot{\footnotesize \parbox{11cm}{\textit{#2}}}
\rfoot{\footnotesize Page \thepage\ of \pageref{LastPage}}
\renewcommand\headheight{24pt}
\renewcommand\footrulewidth{0.4pt}

然而,使用\documentclass{letter}时,这根本不起作用。欢迎提供建议。

编辑: 这里是示例代码,但它没有任何明显的原因可以工作:

\documentclass[12pt]{letter}

\usepackage{fontspec}% font selecting commands 
\usepackage{xunicode}% unicode character macros 
\usepackage{xltxtra} % some fixes/extras 

% page counting, header/footer
\usepackage{fancyhdr}
\usepackage{lastpage}

\pagestyle{fancy}
\lhead{\footnotesize \parbox{11cm}{Draft 1} }
\lfoot{\footnotesize \parbox{11cm}{\textit{2}}}
\cfoot{}
\rhead{\footnotesize 3}
\rfoot{\footnotesize Page \thepage\ of \pageref{LastPage}}
\renewcommand{\headheight}{24pt}
\renewcommand{\footrulewidth}{0.4pt}

\begin{document}
\name{ Joe Laroo }
\signature{ Joe Laroo }
\begin{letter}{ To-Address }
\renewcommand{\today}{ February 16, 2009 }
\opening{ Opening }
Content of the letter.
\closing{ Yours truly, }
\end{letter}
\end{document}

fancyhdr 应该 可以工作。当您尝试时发生了什么? - Charlie Martin
我的想法完全一样。我已经编辑了问题,添加了我认为应该可以工作的非功能性代码... - Brian M. Hunt
错误和/或如何失败的图片或解释可能是有益的。是的,我可以复制它并尝试自己,但我很懒... - dmckee --- ex-moderator kitten
4个回答

25

在你的“Content of the letter”行之前,添加\thispagestyle{fancy},它应该会显示你定义的页眉。(这对我起作用了。)

这是我用来测试的完整文档:

\documentclass[12pt]{letter}

\usepackage{fontspec}% font selecting commands 
\usepackage{xunicode}% unicode character macros 
\usepackage{xltxtra} % some fixes/extras 

% page counting, header/footer
\usepackage{fancyhdr}
\usepackage{lastpage}

\pagestyle{fancy}
\lhead{\footnotesize \parbox{11cm}{Draft 1} }
\lfoot{\footnotesize \parbox{11cm}{\textit{2}}}
\cfoot{}
\rhead{\footnotesize 3}
\rfoot{\footnotesize Page \thepage\ of \pageref{LastPage}}
\renewcommand{\headheight}{24pt}
\renewcommand{\footrulewidth}{0.4pt}

\usepackage{lipsum}% provides filler text

\begin{document}
\name{ Joe Laroo }
\signature{ Joe Laroo }
\begin{letter}{ To-Address }
\renewcommand{\today}{ February 16, 2009 }
\opening{ Opening }

\thispagestyle{fancy}% sets the current page style to 'fancy' -- must occur *after* \opening
\lipsum[1-10]% just dumps ten paragraphs of filler text

\closing{ Yours truly, }
\end{letter}
\end{document}

\opening命令将页面样式设置为firstpageempty,因此您必须在该命令之后使用\thispagestyle


1

我移除之后

\usepackage{fontspec}% font selecting commands 
\usepackage{xunicode}% unicode character macros 
\usepackage{xltxtra} % some fixes/extras 

看起来它已经“正确地”工作了。

值得注意的是,页眉和页脚只出现在第二页及以后。虽然我已经尝试了fancyhdr文档中提供的修复方法,但也无法使其工作。

FYI:Vista下的MikTeX 2.7


使用这些usepackages只能在xe(la)tex中工作-抱歉,我应该提到一下。 - Brian M. Hunt

1
关于Brent.Longborough的回答(仅在第2页及以后出现),也许您需要在\begin{document}之后设置\thispagestyle{}。我想知道信件类是否将第一页样式设置为空。

0

这段代码可以在第一页插入页眉和页脚,其中页眉居中对齐,页脚左对齐

\makeatletter
\let\old@ps@headings\ps@headings
\let\old@ps@IEEEtitlepagestyle\ps@IEEEtitlepagestyle
\def\confheader#1{%
  % for the first page
  \def\ps@IEEEtitlepagestyle{%
    \old@ps@IEEEtitlepagestyle%
    \def\@oddhead{\strut\hfill#1\hfill\strut}%
    \def\@evenhead{\strut\hfill#1\hfill\strut}%
 \def\@oddfoot{\mycopyrightnotice}
  \def\@evenfoot{}
  }%
  \ps@headings%
}
\makeatother

\confheader{%
  5$^{th}$  IEEE International Conference on Recent Advances and Innovations in Engineering - ICRAIE 2020 (IEEE Record\#51050) %EDIT HERE
}

\def\mycopyrightnotice{
  {\footnotesize XXX-1-7281-8867-6/20/\$31.00~\copyright~2020 IEEE\hfill} % EDIT HERE
  \gdef\mycopyrightnotice{}

}

\newcommand*{\affmark}[1][*]{\textsuperscript{#1}}


\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\newcommand{\ma}[1]{\mbox{\boldmath$#1$}} ```

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接