3

I have a list of addresses. How can I print those such that I can print those and glue to envelopes? I mean, I would like that every page has three addresses in every row and eight addresses in every column, like this

firstname1 surname1   firstname2 surname2   firstname3 surname3
streetaddress1        streetaddress2        streetaddress3
zip1 city1            zip2 city2            zip3 city3

firstname4 surname4   firstname5 surname5   firstname6 surname6
streetaddress4        streetaddress5        streetaddress6
zip4 city4            zip5 city5            zip6 city6

...

firstname22 surname22 firstname23 surname23 firstname24 surname24
streetaddress22       streetaddress23       streetaddress24
zip22 city22          zip23 city23          zip24 city24

and the final page would be filled from left to right, like this:

firstname25 surname25 firstname26 surname26 firstname27 surname27
streetaddress25       streetaddress26       streetaddress27
zip25 city25          zip26 city26          zip2 city27

firstname28 surname28
streetaddress28
zip28 city28
  • 4
    Welcome to TeX.SX. Great user name. Do you ever hang out here? – Ian Thompson Nov 6 '14 at 21:13
  • I have never been there. – envelopist Nov 6 '14 at 21:22
2

You can use a minipage and size it appropriately where I have used the pgffor package was used just to create a simple loop to demonstrate the technique.

If you store the files in a CSV file as:

Stephen P Jobs, 1 Infinite Loop, Cupertino, CA 95014
Tim Cook, 1 Infinite Loop, Cupertino, CA 95014
Larry Page, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
Sergey Brin, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
Erich Schmidt, 1600 Amphitheatre Pkwy, Mountain View, CA 94043

then you can use the the datatool package to read in the CSV file. This produces:

enter image description here

Notes:

  • The filecontents package was used to set up a file to read for this test case. It is not needed in you actual use case.

Code: Demonstration

\documentclass{article}
\usepackage{pgffor} 

\newcommand*{\NewAddress}[1]{%
\noindent
\begin{minipage}[t][0.12\textheight]{0.33\linewidth}
\begin{tabular}{@{}l@{}}
    #1
\end{tabular}%
\end{minipage} % <-- Need space here
}

\begin{document}
\foreach \x in {1,...,128} {%
    \NewAddress{%
        firstname1 surname1 \\
        streetaddress1 \\
        zip1 city1  \\
    }%
}
\end{document}

Code: Use CSV File:

\documentclass{article}
\usepackage{pgffor} 
\usepackage{datatool}
\usepackage{times}

\usepackage{filecontents}% <-- Commented out to prevent overwriting address.csv
\begin{filecontents*}{address.csv}
    Stephen P Jobs, 1 Infinite Loop, Cupertino, CA 95014
    Tim Cook, 1 Infinite Loop, Cupertino, CA 95014
    Larry Page, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Sergey Brin, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Erich Schmidt, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Stephen P Jobs, 1 Infinite Loop, Cupertino, CA 95014
    Tim Cook, 1 Infinite Loop, Cupertino, CA 95014
    Larry Page, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Sergey Brin, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Erich Schmidt, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Stephen P Jobs, 1 Infinite Loop, Cupertino, CA 95014
    Tim Cook, 1 Infinite Loop, Cupertino, CA 95014
    Larry Page, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Sergey Brin, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Erich Schmidt, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Stephen P Jobs, 1 Infinite Loop, Cupertino, CA 95014
    Tim Cook, 1 Infinite Loop, Cupertino, CA 95014
    Larry Page, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Sergey Brin, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Erich Schmidt, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Stephen P Jobs, 1 Infinite Loop, Cupertino, CA 95014
    Tim Cook, 1 Infinite Loop, Cupertino, CA 95014
    Larry Page, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Sergey Brin, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Erich Schmidt, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Stephen P Jobs, 1 Infinite Loop, Cupertino, CA 95014
    Tim Cook, 1 Infinite Loop, Cupertino, CA 95014
    Larry Page, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Sergey Brin, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Erich Schmidt, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Stephen P Jobs, 1 Infinite Loop, Cupertino, CA 95014
    Tim Cook, 1 Infinite Loop, Cupertino, CA 95014
    Larry Page, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Sergey Brin, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Erich Schmidt, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Stephen P Jobs, 1 Infinite Loop, Cupertino, CA 95014
    Tim Cook, 1 Infinite Loop, Cupertino, CA 95014
    Larry Page, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Sergey Brin, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Erich Schmidt, 1600 Amphitheatre Pkwy, Mountain View, CA 94043
    Stephen P Jobs, 1 Infinite Loop, Cupertino, CA 95014
\end{filecontents*}


\newcommand*{\NewAddress}[1]{%
\noindent
\begin{minipage}[t][0.12\textheight]{0.33\linewidth}
\begin{tabular}{@{}l@{}}
    #1
\end{tabular}%
\end{minipage} % <-- Need space here
}

\begin{document}
\DTLloaddb[noheader,keys={Name,Address,City,StateAndZip}]{myDB}{address.csv}
\DTLforeach*{myDB}{\Name=Name,\Address=Address,\City=City, \StateAndZip=StateAndZip}{%
    \NewAddress{%
        \Name \\
        \Address, \\
        \City, \\
        \StateAndZip  \\
    }%
}%
\end{document}
3

The labels package in combination with textmerg is very useful for this. I use this to print pages of labels on a laser printer but you could obviously print on ordinary paper and cut them out and glue if preferred.

The address details are kept in a separate file, included here using filecontents.

\documentclass{article}
\usepackage{textmerg}                                                                                                           \usepackage[newdimens]{labels}
\usepackage{filecontents}% insists on writing comments to first 4 lines of file for some reason so need dummy text on first line which can be discarded below
\begin{filecontents*}{\jobname.dat}
    firstname1
    surname1
    address1
    zip1
    city1
    firstname2
    surname2
    address2
    zip2
    city2
    firstname3
    surname3
    address3
    zip3
    city3
    firstname4
    surname4
    address4
    zip4
    city4
    firstname5
    surname5
    address5
    zip5
    city5
    firstname6
    surname6
    address6
    zip6
    city6
    firstname7
    surname7
    address7
    zip7
    city7
    firstname8
    surname8
    address8
    zip8
    city8
    firstname9
    surname9
    address9
    zip9
    city9
    firstname10
    surname10
    address10
    zip10
    city10
    firstname11
    surname11
    address11
    zip11
    city11
    firstname12
    surname12
    address12
    zip12
    city12
    firstname13
    surname13
    address13
    zip13
    city13
    firstname14
    surname14
    address14
    zip14
    city14
    firstname15
    surname15
    address15
    zip15
    city15
    firstname16
    surname16
    address16
    zip16
    city16
    firstname17
    surname17
    address17
    zip17
    city17
    firstname18
    surname18
    address18
    zip18
    city18
    firstname19
    surname19
    address19
    zip19
    city19
    firstname20
    surname20
    address20
    zip20
    city20
    firstname21
    surname21
    address21
    zip21
    city21
    firstname22
    surname22
    address22
    zip22
    city22
    firstname23
    surname23
    address23
    zip23
    city23
    firstname24
    surname24
    address24
    zip24
    city24
    firstname25
    surname25
    address25
    zip25
    city25
    firstname26
    surname26
    address26
    zip26
    city26
    firstname27
    surname27
    address27
    zip27
    city27
    firstname28
    surname28
    address28
    zip28
    city28
\end{filecontents*}


\LabelCols=3
\LabelRows=8
\LeftPageMargin=4.5mm
\RightPageMargin=4.5mm
\TopPageMargin=13mm
\BottomPageMargin=13mm
\InterLabelColumn=2.5mm
\InterLabelRow=0mm
\RightLabelBorder=5mm
\LeftLabelBorder=5mm
\TopLabelBorder=5mm
\BottomLabelBorder=5mm

% \LabelGridtrue %turn on to line stuff up; off to process final version
\numberoflabels=1

\begin{document}

  \Fields{\firstname\surname\address\zip\city}

  \Merge{\jobname.dat}{%
      \addresslabel[\small\sffamily]{%
        \firstname\ \surname\\\address\\\zip\ \city
      }%
  }


\end{document}

28 labels

  • 1
    Use can use filecontents* to avoid the comments. – Peter Grill Nov 6 '14 at 22:38
  • @PeterGrill I didn't know that. Thanks - most useful. – cfr Nov 6 '14 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.