3.6 ⁑Envelopes
The letter class defines a preamble-only command:
which gathers the addresses of all the recipients and generates address labels at the end of the document. These labels can then be stuck onto the envelopes.
For example, the document from Example 17 had
six pages, one page for each letter. If you add \makelabels
to the preamble of that document, a seventh sheet will be generated
with the address labels, shown in Figure 3.6.
This is fine if this matches the size of your label sheets, but it can't be easily adapted for other label sizes. There are some envelope-related packages listed on the letter topic but take care as some of them, such as envelope, were written for LaTeX2.09 and may not work as well with LaTeX2e or licensing issues may prevent them from being included in TeX Live.
Some of the other letter-like classes also provide envelope labelling facilities, but there are two packages that are both in the TeX Live and MiKTeX distributions: envlab and envbig. Another possibility is to use the ticket package, which is discussed in §10.2 The ticket Package.
The user guide for envlab [111] can be obtained via:
Note that texdoc envlab produces the documented source code, which you may find more complicated than the user guide. There's no proper manual for envbig; texdoc envbig just opens the README file. You need to open envbig.sty in your text editor and read the comments for an example of how to use the package. Therefore this book will just look at envlab. At the time of writing, the current version of envlab is 1.2 (1997-07-16).
The envlab package is designed for US postal layouts, but it's
possible to define custom label sizes. This package redefines
\makelabels
but it's used in the same way as for the
letter class.
The envlab package is configured for three different types of
media: envelopes (one per page, optionally rotated), labels (without
a return address) and big labels (with a return address). Envelopes
are usually printed in landscape format. This rotation can be
switched on or off using the rotateenvelopes
or
norotateenvelopes
options.
The envelope layout can be set by the package options listed in Table 3.4 or a custom size can be set via:
where ⟨top margin⟩ is the height of the top margin, ⟨width⟩ is the envelope width and ⟨height⟩ is the envelope height.
The standard label layout can be set by the package options listed in Table 3.5 or a custom size can be set via:
where ⟨width⟩ is the total width from the left border of one label and the left border of the label in the next column, ⟨height⟩ is the total height from the top border of one label and the top border of the label in the row below, ⟨top⟩ and ⟨left⟩ are the distances between the edge of the paper and the label, ⟨sep⟩ is the horizontal distance between labels and ⟨columns⟩ and ⟨rows⟩ are the number of columns and rows of labels per page.
The big label layout can be set by the package options listed in Table 3.6 or a custom size can be set via:
The arguments are the same as for \SetLabel
.
If you have a partially used sheet, you can specify the starting label via:
where ⟨row⟩ is the row index (starting from 1) and ⟨column⟩ is the column index (starting from 1). The labels are printed row by row.
The return address for the big envelopes is taken from the
argument of \address
but this can be changed by redefining:
This can be changed to the textual address or it can use
\includegraphics
to use a company logo.
This example creates a letter using the letter class but uses the envlab package to create a custom sized big label.
\documentclass{letter} \usepackage[a4paper]{geometry} \usepackage[british]{babel} \usepackage{envlab} \SetBigLabel{101mm}{139mm}{9mm}{3mm}{2mm}{2}{2} \makelabels \name{Mr Big Head} \signature{Big Head} \location{Secret Lab of Experimental Stuff} \address{University of Somewhere\\Some City\\AB3 4YZ} \telephone{0123456789} \begin{document} \begin{letter}{Miss Polly Parrot\\42 The Lane\\Some Town\\AB1 2XY} \opening{Dear Miss Parrot} \thispagestyle{firstpage} This is an imaginary letter. This is the second paragraph of the letter. \closing{Yours sincerely} \ps PS: this is a postscript. \encl{Photocopy of something interesting\\ Photocopy of something rather dull} \cc{Prof Important Person\\Dr Bor Ing} \end{letter} \end{document}
This produces a document with two pages. The first contains the letter and the second contains the label. This second page is shown in Figure 3.7.
This produces a portrait label, but if you have a wide address it may look
better rotated to make a landscape label. Unfortunately, the envlab
options that govern rotation (rotateenvelope
and
norotateenvelope
) don't apply to labels.
These big labels are implicitly typeset using
where ⟨from-address⟩ is the sender's address and ⟨to-address⟩ is the recipient's address. This command is defined as:
\newcommand{\PrintBigLabel}[2]{% \begin{minipage}[t][\LabelHeight]{\LabelWidth}% \baselineskip=0pt% \lineskip=0pt% \parindent=0pt% \begin{center}% \PrintReturnAddress{#1}\\% \rule{\ToAddressWidth}{0.1pt}% \PrintAddress{#2}% \end{center}% \end{minipage}}
This displays the label in a minipage
with the dimensions given
by \LabelWidth
and \LabelHeight
which
have been set to the width and height of the printable label area.
This can be redefined to provide your own custom label format. For
example (recall \rotatebox
provided by the graphicx
package [14] described in Volume 1):
\renewcommand{\PrintBigLabel}[2]{% \begin{minipage}[t]{\LabelHeight}{\LabelWidth} \vfill \hspace*{1em}% \rotatebox[origin=l]{90}{\PrintReturnAddress{#1}}\hfill \rule{0.1pt}{\ToAddressWidth}\space \rotatebox[origin=l]{90}{\PrintAddress{#2}}% \hspace*{1em}% \vfill \end{minipage}% }
This now produces the label shown in Figure 3.8. You can further customize this redefinition if you like. For example, you may want the recipient's address above the return address. You can download or view this example document.
capaddress
package
option doesn't work with extended characters unless they have been
placed inside a group, which will cause
a problem with some of the entries in the sample people.csv file or
the people SQL table. This means that if we want to adapt
Example 17 to use envlab, we have to
switch off the capitalisation feature using the
nocapaddress
package option.
Example:
\documentclass{letter} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[nocapaddress]{envlab} \makelabels \begin{document} \begin{letter}{Ms Zöe Zebra\\856 The Avenue} \opening{Dear Miss Parrot} A sample letter. \closing{Yours sincerely} \end{letter} \end{document}
With the nocapaddress
option, this code compiles
without error. With the default capaddress
option, the
ö must be placed inside a group:
(For those of you who have used glossaries or mfirstuc, it stems from a similar issue. See the section “UTF-8” in the mfirstuc documentation [99].)
Alternatively use XeLaTeX instead of PDFLaTeX (the inputenc and fontenc packages need to be replaced by the fontspec [76] package):
% arara: xelatex \documentclass{letter} \usepackage{fontspec} \usepackage{envlab} \makelabels \begin{document} \begin{letter}{Ms Zöe Zebra\\856 The Avenue} \opening{Dear Miss Parrot} A sample letter. \closing{Yours sincerely} \end{letter} \end{document}
The above can be put together to form a complete document that contains the correspondence and the large mailing labels:
\documentclass{letter} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[a4paper]{geometry} \usepackage[british]{babel} \usepackage{datatool} \usepackage{graphicx} \usepackage[nocapaddress]{envlab} \DTLloaddb{people}{people.csv} \DTLloaddb{countries}{country-codes.csv} \SetBigLabel{101mm}{139mm}{9mm}{3mm}{2mm}{2}{2} \renewcommand{\PrintBigLabel}[2]{% \begin{minipage}[t][\LabelHeight]{\LabelWidth}% \vfill \hspace*{1em}% \rotatebox[origin=l]{90}{\PrintReturnAddress{#1}}\hfill \rule{0.1pt}{\ToAddressWidth}\space \rotatebox[origin=l]{90}{\PrintAddress{#2}}% \hspace*{1em}% \vfill \end{minipage}% } \makelabels \name{Mr Big Head} \signature{Big Head} \location{Secret Lab of Experimental Stuff} \address{University of Somewhere\\Some City\\AB3 4YZ} \telephone{0123456789} \begin{document} \DTLforeach*{people}% data {% assignments \Id=id,% \Surname=surname,% \Forenames=forenames,% \Title=title,% \AddressI=address1,% \AddressII=address2,% \Town=town,% \County=county,% \Postcode=postcode,% \CountryCode=country% } {% \xDTLassignfirstmatch{countries}{code}{\CountryCode}{\CountryName=name} \begin{letter}{\DTLifnullorempty{\Title}{}{\Title\␣}% \Forenames\␣\Surname\\\AddressI\\ \DTLifnullorempty{\AddressII}{}{\AddressII\\}\Town\\ \DTLifnullorempty{\County}{}{\County\\}\Postcode\\\CountryName} \opening{Dear \DTLifnullorempty{\Title}{\Forenames}{\Title} \Surname} \thispagestyle{firstpage} This is an imaginary letter. This is the second paragraph of the letter. \closing{Yours sincerely} \ps PS: this is a postscript. \encl{Photocopy of something interesting\\ Photocopy of something rather dull} \cc{Prof Important Person\\Dr Bor Ing} \end{letter} } \end{document}
The newlfm class automatically loads the envlab class.
There's a class option useenvlab
that's designed to
activate the envlab functions but its use seems to be designed
to work with newlfm's mechanism for storing addresses in an
external file called letrinfo.tex. This doesn't fit in with
the generic mail-merging functions discussed here, so instead we'll
look at how to manually make address labels with envlab. This
method can be applied to other classes or you can use this method if
you just want to generate labels without a corresponding letter.
For the manual method, when you want to start typesetting the labels you need to use:
Then you use
for each label where ⟨from-address⟩ is the sender's address and ⟨to-address⟩ is the recipient's address.
If you use the manual approach, you must generate the labels after you've finished typesetting the letters. This example illustrates this manual approach to generate letters and corresponding labels to everyone in the sample people.csv file database or the people SQL table who has the subscribed field set:
\documentclass[stdletter,nocapaddress,avery5164biglabel]{newlfm} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[british]{babel} \usepackage{datatool} \newcommand{\ifcsbool}[3]{% \ifboolexpr { test{\ifdefstring{#1}{true}} or test{\ifdefstring#1{1}} } {#2}{#3}% } \DTLloaddb{people}{people.csv} \DTLloaddb{countries}{country-codes.csv} \newlfmP{orderfromtodate,sigcenter,addrfromphone,addrfromemail} \namefrom{Mr Big Head} \addrfrom{University of Somewhere\\Some City\\AB3 4YZ} \emailfrom{big.head@somewhere.ac.uk} \phonefrom{0123456789} \regarding{A sample letter} \closeline{Yours sincerely} \cclist{Prof Important Person\\Dr Bor Ing} \encllist{Photocopy of something interesting\\ Photocopy of something rather dull} \psitem{this is a postscript} \begin{document} \DTLforeach*{people}% data {% assignments \Id=id,% \Surname=surname,% \Forenames=forenames,% \Title=title,% \AddressI=address1,% \AddressII=address2,% \Town=town,% \County=county,% \Postcode=postcode,% \CountryCode=country,% \Subscribed=subscribed% } {% \ifcsbool{\Subscribed} {% \xDTLassignfirstmatch{countries}{code}{\CountryCode}{\CountryName=name} \nameto{\DTLifnullorempty{\Title}{}{\Title\␣}\Forenames\␣\Surname} \addrto{% \AddressI\\ \DTLifnullorempty{\AddressII}{}{\AddressII\\}\Town\\ \DTLifnullorempty{\County}{}{\County\\}\Postcode\\\CountryName } \greetto{Dear \DTLifnullorempty{\Title}{\Forenames}{\Title} \Surname} \begin{newlfm} This is an imaginary letter. This is the second paragraph of the letter. \end{newlfm} }% {}% not subscribed } \startlabels \DTLforeach*{people}% data {% assignments \Id=id,% \Surname=surname,% \Forenames=forenames,% \Title=title,% \AddressI=address1,% \AddressII=address2,% \Town=town,% \County=county,% \Postcode=postcode,% \CountryCode=country,% \Subscribed=subscribed% } {% \ifcsbool{\Subscribed} {% \xDTLassignfirstmatch{countries}{code}{\CountryCode}{\CountryName=name} \mlabel {Mr Big Head\\University of Somewhere\\Some City AB3 4YZ}% {\DTLifnullorempty{\Title}{}{\Title\␣}\Forenames\␣\Surname\\% \AddressI\\ \DTLifnullorempty{\AddressII}{}{\AddressII\\}\Town\\ \DTLifnullorempty{\County}{}{\County\\}\Postcode\\\CountryName } }% {}% not subscribed } \end{document}
There is some duplicate code in the previous example that's
inefficient, especially if you have a large database.
For this exercise, rewrite the document from
Example 21 so that it only has one
instance of each of the commands \DTLforeach
and \xDTLassignfirstmatch
and only
one test for each member's subscribed status. Hint: recall the hook
management described in §2.1.2 Hook Management. If you're feeling
adventurous try to make the address on the labels upper case without using
envlab's case-changing function. (Recall \MakeUppercase
from Volume 2.)
This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).