About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Smile for the Camera: a new cybercrime short story ebook.


3.6 Envelopes

The letter class defines a preamble-only command:

\makelabels

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.

Figure 3.6: Address Labels
 
Miss Polly Parrot
42 The Lane
Some Town
Noshire
AB1 2XY
United Kingdom

Mrs Mabel Canary
24 The Street
Some Village
Some Town
Noshire
AB1 2YZ
United Kingdom

Ms Zöe Zebra
856 The Avenue
Some City
CA
123456
United States

José Arara
Nenhuma Rua
São Paulo
123457
Brazil

Mr Dickie Duck
1 The Street
Another Village
Some City
Imagineshire
YZ1 2AB
United Kingdom

Mr Fred Canary
24 The Street
Some Village
Some Town
Noshire
AB1 2YZ
United Kingdom
(The first five addresses are in the first column. The final address is at the start of the second column.) End of Image.

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:

texdoc elguide

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:

\SetEnvelope[top margin]{width}{height}

where ⟨top margin⟩ is the height of the top margin, ⟨width⟩ is the envelope width and ⟨height⟩ is the envelope height.


Table 3.4: Envelope Options for the envlab Package
Option Width Height
businessenvelope 9.5 in 4.125 in
executiveenvelope 7.5 in 3.875 in
bookletenvelope 10.5 in 7.5 in
personalenvelope 6.5 in 3.625 in
c6envelope 162 mm 114 mm
c65envelope 224 mm 114 mm
c5envelope 229 mm 162 mm
dlenvelope 220 mm 110 mm

The standard label layout can be set by the package options listed in Table 3.5 or a custom size can be set via:

\SetLabel{width}{height}{top}{left}{sep}{columns}{rows}

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.


Table 3.5: Standard Label Options for the envlab Package
 Option Width Height Top Left Sep Cols Rows  
 avery5160label 2.75 in 1 in 0.5 in 0.19 in 0.12 in 3 10  
 avery5161label 4.19 in 1 in 0.5 in 0.16 in 0.19 in 2 10  
 avery5162label 4.19 in 1.33 in 0.83 in 0.16 in 0.19 in 2 7  
 avery5163label 4.19 in 2 in 0.5 in 0.16 in 0.19 in 2 5  
 avery5164label 4.19 in 3.33 in 0.5 in 0.16 in 0.19 in 2 3  
 avery5262label 110 mm 34 mm 21 mm 4 mm 5 mm 2 7  
 herma4625label 105 mm 42.3 mm 0 mm 5 mm 5 mm 2 7  

The big label layout can be set by the package options listed in Table 3.6 or a custom size can be set via:

\SetBigLabel{width}{height}{top}{left}{sep}{columns}{rows}

The arguments are the same as for \SetLabel.


Table 3.6: Big Label Options for the envlab Package
Option Width Height Top Left Sep Cols Rows
avery5163biglabel 4.19 in 2 in 0.5 in 0.16 in 0.19 in 2 5
avery5164biglabel 4.19 in 3.33 in 0.5 in 0.16 in 0.19 in 2 3

If you have a partially used sheet, you can specify the starting label via:

\FirstLabel{row}{column}

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:

\returnaddress

This can be changed to the textual address or it can use \includegraphics to use a company logo.

Example 19. Envelope Labels

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.

Figure 3.7: Custom Big Label
 

University of Somewhere
Some City
AB3 4YZ






MISS POLLY PARROT
42 THE LANE
SOME TOWN
AB1 1XY End of Image.

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

\PrintBigLabel{from-address}{to-address}

where ⟨from-address⟩ is the sender's address and ⟨to-address⟩ is the recipient's address. This command is defined as:

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):

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.

Figure 3.8: Custom Formatted Big Label
 

University of Somewhere
Some City
AB3 4YZ






MISS POLLY PARROT
42 THE LANE
SOME TOWN
AB1 1XY

(Rotated 90 degrees anticlockwise.) End of Image.

Unfortunately the default 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:

\begin{letter}{Ms Z{ö}e Zebra\\856 The Avenue}

(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}

Example 20. Mail Merging with letter and envlab

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}

You can download or view this 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:

\startlabels

Then you use

\mlabel{from-address}{to-address}

for each label where ⟨from-address⟩ is the sender's address and ⟨to-address⟩ is the recipient's address.

Example 21. Mail Merging with newlfm, envlab and datatool

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}

You can download or view this document.

Exercise 11. Mail Merging With Envelope Labels Using newlfm, envlab and datatool

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.)

You can download or view the solution.


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs