Skip to content

Instantly share code, notes, and snippets.

@ObjectBoxPC
Created January 30, 2022 10:23
Show Gist options
  • Save ObjectBoxPC/8b026fe5e9b19d693477aa0d679fd366 to your computer and use it in GitHub Desktop.
Save ObjectBoxPC/8b026fe5e9b19d693477aa0d679fd366 to your computer and use it in GitHub Desktop.
XeLaTeX template document for printing addresses on envelopes
%Note on rotation: It may be a good idea to rotate the page when printing,
%so that the envelope is in a "portrait" orientation in the printer.
%I tried to use lscape to rotate the text, but that doesn't seem to work with textpos.
%The solution for now is to use an external tool like pdftk
%or the settings in some PDF viewers and printer drivers.
%Suggestions on how to achieve proper rotation in TeX are welcome.
%Settings
%Envelope dimensions (in inches) (US #10 envelopes are 9 1/2 in. x 4 1/8 in.)
\newcommand{\envelopewidth}{9.5}
\newcommand{\envelopeheight}{4.125}
%Font for addresses
\newcommand{\addressfont}{FreeSans}
%Font sizes
\newcommand{\returnaddressfontsize}{12}
\newcommand{\destinationaddressfontsize}{16}
%Line spacing
\newcommand{\addresslinespacing}{1.25}
%Positions for address blocks (in inches)
\newcommand{\returnaddressx}{0.5}
\newcommand{\returnaddressy}{0.5}
\newcommand{\destinationaddressx}{4}
\newcommand{\destinationaddressy}{2}
\documentclass{article}
\usepackage{calc}
\usepackage{fontspec}
\usepackage[paperwidth=\envelopewidth in,paperheight=\envelopeheight in]{geometry}
\usepackage[absolute]{textpos}
\setmainfont{\addressfont}
%Remove paragraph indentation
\setlength{\parindent}{0in}
%Set base lengths for textblock environment so that positions can be given in inches
\setlength{\TPHorizModule}{1in}
\setlength{\TPVertModule}{1in}
%No page numbers
\pagestyle{empty}
\begin{document}
%Return address
\begin{textblock}{5}(\returnaddressx, \returnaddressy)
%Set font size
\addfontfeatures{SizeFeatures={Size=\returnaddressfontsize}}
%Explicitly set baselineskip because other approaches do not seem to scale the spacing properly for different font sizes
\setlength{\baselineskip}{\returnaddressfontsize pt * \real{\addresslinespacing}}
Example Industries \\
123 Main St. \\
Sample City, NA 12345-6789
\end{textblock}
%Destination address
\begin{textblock}{5}(\destinationaddressx, \destinationaddressy)
\addfontfeatures{SizeFeatures={Size=\destinationaddressfontsize}}
\setlength{\baselineskip}{\destinationaddressfontsize pt * \real{\addresslinespacing}}
Example Person \\
4567 Hill Ave. \\
Sampleton, AN 98765-4321
\end{textblock}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment