有时,平凡的事情反而最让人头疼。不过,借助于进化出的、用户友好的模板,这一切并不需要如此复杂。幸运的是,LaTeX 使得写信变得非常快捷,而且几乎没有麻烦。

信件类

要写信,可以使用标准的 letter 文档类。

你可以在一个 LaTeX 文件中写多封信——每封信以 \begin{letter}{''recipient''} 开始,以 \end{letter} 结束。收件人可以为空。每封信由四个部分组成:

  1. 开头(比如 \opening{Dear Sir or Madam,}\opening{Dear Kate,})。

  2. 正文(像往常一样在 LaTeX 中书写)。如果你想在所有信件中使用相同的正文,可以考虑将整个正文放在一个新命令中,如 \newcommand{\BODY}{actual body},然后在所有信件中使用 \BODY

  3. 结束语(比如 \closing{Yours sincerely,})。

  4. LaTeX 会在结束语后留下一些空白,用于你的手写签名;接着它会加上你的名字和姓氏,如果你已经声明了它们。

  5. 额外元素:附言、抄送和附件列表。

如果你希望信件中显示你的姓名、地址和电话号码,你必须首先声明它们,格式为:签名、地址和电话。

输出的信件看起来将是这样的:


示例信件

这是示例的代码:

\documentclass{letter}
\usepackage{hyperref}
\signature{Joe Bloggs}
\address{21 Bridge Street \\ Smallville \\ Dunwich DU3 4WE}
\begin{document}

\begin{letter}{Director \\ Doe \& Co \\ 35 Anthony Road
\\ Newport \\ Ipswich IP3 5RT}
\opening{Dear Sir or Madam:}

I am writing to you on behalf of the Wikipedia project (http://www.wikipedia.org/),
an endeavour to build a fully-fledged multilingual encyclopaedia in an entirely
open manner, to ask for permission to use your copyrighted material.

% The \ldots command produces dots in a way that will not upset
% the typesetting of the document.
\ldots 

That said, allow me to reiterate that your material will be used to the noble end of
providing a free collection of knowledge for everyone; naturally enough, only if you
agree. If that is the case, could you kindly fill in the attached form and post it
back to me? We shall greatly appreciate it.

Thank you for your time and consideration.

I look forward to your reply.

\closing{Yours Faithfully,}

\ps

P.S. You can find the full text of GFDL license at
\url{http://www.gnu.org/copyleft/fdl.html}.

\encl{Copyright permission form}

\end{letter}
\end{document}

要将结束部分和签名部分移到左侧,请在 \begin{document} 之前插入以下内容:

\longindentation=0pt

可以通过增加 0pt 来调整左侧的空间量。

信封

使用 envlab 包

envlab 包提供了对 \makelabels 命令的定制,使用户能够在多种标签或信封尺寸上打印。例如,按以下方式开始你的 LaTeX 文件,会生成一个文档,其中包括信件和接下来的一页上的商业尺寸(#10)信封。

\documentclass{letter}
\usepackage[businessenvelope]{envlab}
\makelabels

有关此功能强大的包的更多信息,请参考 envlab 用户指南。请注意,envlab 包在显示非基本 ASCII 字符集的字符时存在问题,详情请参见此 bug 报告。

使用 geometry 包

以下是一个使用 geometry 包的简单信封,它通过简化页面(及页面本身)上的内容重新排版任务来非常方便。

% envelope.tex
\documentclass{letter}
\usepackage[left=1in,top=0.15in,papersize={4.125in,9.5in},landscape,twoside=false]{geometry}
\setlength\parskip{0pt}
\pagestyle{empty}

\begin{document}

FROM-NAME

FROM-STREET ADDRESS

FROM-CITY, STATE, \ ZIP

\vspace{1.0in}\large
\setlength\parindent{3.6in}

TO-NAME

TO-STREET ADDRESS

TO-CITY, STATE, \ ZIP

\end{document}

打印

上述设置可以处理间距,但实际的打印过程则取决于你和打印机之间的配置。某个用户报告说,使用 envlab 创建的信封打印相对简单。如果你使用 geometry 包,可能会发现以下命令对于打印信封非常有用:

$ pdflatex envelope.tex
$ pdf2ps envelope.pdf
$ lpr -o landscape envelope.ps

或者,你可以使用 latex 的 dvi 输出驱动程序。

第一行中,dvips 命令将 latex 生成的 .dvi 文件转换为 .ps(PostScript)文件。第二行将 PostScript 文件发送到打印机:

$ latex envelope.tex && dvips -t unknown -T 9.5in,4.125in envelope.dvi
$ lpr -o landscape envelope.ps

据报告,虽然 geometry 手册中说 dvips 会创建正确的页面大小,但它实际上不会工作,除非调整打印机设置为正确的页面样式。这些设置取决于你使用的打印机过滤器,在 CUPS 中,可能会在 lpr 命令行中提供。

窗口信封

使用 KOMA 包中的 letter 类是单独打印地址的另一种方法。它支持额外的功能,比如折叠标记和适合窗口信封的正确地址放置。使用 KOMA 包中的 scrlttr2 文档类,示例信件代码如下:

% koma_env.tex
\documentclass[a4paper]{scrlttr2}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{url}

\setkomavar{fromname}{Joe Bloggs}
\setkomavar{fromaddress}{21 Bridge Street\\ Smallville\\ Dunwich DU3 4WE}
\setkomavar{fromphone}{0123 45679}

\begin{document}

\begin{letter}{Director \\ Doe \& Co \\ 35 Anthony Road
\\ Newport \\ Ipswich IP3 5RT}

\KOMAoptions{fromphone=true,fromfax=false}
\setkomavar{subject}{Wikipedia}
\setkomavar{customer}{2342}
\opening{Dear Sir or Madam,}

I am writing to you on behalf of the Wikipedia project
(\url{http://www.wikipedia.org/}), an endeavour to build a
fully-fledged multilingual encyclopaedia in an entirely open
manner, to ask for permission to use your copyrighted material.

\ldots 

That said, allow me to reiterate that your material will be used
to the noble end of providing a free collection of knowledge for
everyone; naturally enough, only if you agree. If that is the
case, could you kindly fill in the attached form and post it back
to me? We shall greatly appreciate it.

Thank you for your time and consideration.

I look forward to your reply.

\closing{Yours Faithfully,}
\ps{P.S. You can find the full text of GFDL license at
\url{http://www.gnu.org/copyleft/fdl.html}.}
\encl{Copyright permission form}

\end{letter}

\end{document}

输出通过以下命令生成:

$ pdflatex koma_env

根据折叠标记折叠生成的文件 koma_env.pdf,它可以被放入标准化的窗口信封,DIN C6/5、DL、C4、C5 或 C6。

除了默认设置外,KOMA 包还包含为不同的标准瑞士和日本信函格式预定义的格式定义。

参考:letter.cls 命令

命令 描述
\name{} 设置发件人姓名
\signature{} 设置签名
\address{} 设置地址
\location{} 设置位置
\telephone{} 设置电话号码
\makelabels 生成标签
\stopbreaks 停止自动换行
\startbreaks 开始自动换行
\opening{} 设置开头
\closing{} 设置结束
\cc{} 开始一个由 \ccname 引入的段落
\encl{} 开始一个由 \enclname 引入的段落
\ps 开始一个新段落,通常在信件结尾处
\stopletter 结束信件
\returnaddress 返回地址(空)
\startlabels 开始标签(空)
\mlabel{}{}
\descriptionlabel{} 描述标签
\ccname "cc"
\enclname "encl"
\pagename "Page"
\headtoname "To"
\date{} 修改日期,详见 datetime 包
\today 长日期格式

环境描述

环境 描述
letter{} 参见主文章
description 描述环境
verse 诗句环境
quotation 引用环境
quote 引文环境

资源

KOMA-script — 一组多功能的类和包


最后修改: 2025年04月22日 星期二 12:07