# Automating the creation of name badges for an event

We are organizing an event. There will be around 60 participants and I need to prepare name badges (tags) for them.

The badge will involve, name surname and affiliation fields which is different for each participant.

These fields are already in an Excel sheet actually. So, I can easily export them to a csv file.

And there will be a footer with a logo (picture) and the name of the organization.

I want to create a PDF holding 8 or 10 cards per page and then cut with scissors.

I can create the file manually in Word but I don't like to. How can I automate this process in LaTeX?

As an example, here's a simple design that I would like to have:

-
I use datatool.sty to this. – Sigur Jan 20 '13 at 14:37
I have seen a solution with a Visual Basic macro in Excel that generated the namecards on new worksheets. – marczellm Jan 20 '13 at 16:10

ticket package fits very well for this use. The pin example is what you seek for:

%%%%
%
% ticket.sty example file for a pin for conferences
%
%%%%
% use the corresponding paper size for your ticket definition
\documentclass[a4paper,10pt]{letter}

% load ticket.sty with the appropriate ticket definition
\usepackage[freepin,crossmark]{ticket}

\usepackage{graphicx}

% make your default ticket. \ticketdefault is somewhat like a background
\renewcommand{\ticketdefault}{%
\put(50,  3){\includegraphics[width=15mm]{ifmlogoc}}
\put( 5, 13){\line(1,0){60}}
\put( 7, 10){\scriptsize Animal annual meeting (AAM)}
\put( 7,  7){\scriptsize In the gardens}
\put( 7,  4){\scriptsize April 1, 2000}
}

% now what do you like to put in your ticket
\newcommand{\confpin}[2]{\ticket{%
\put(35,36){\makebox[0mm]{\bfseries\Large #1}}
\put(35,28){\makebox[0mm]{\bfseries\large #2}}%
}}

%% the pins for the partipiciants ... ;-)
%% you can generate this part from a database!
\begin{document}
\sffamily
\confpin{Camelus dromedarius}{North Africa}
\confpin{Urocyon cinereoargenteus}{America}
\confpin{Galago moholi}{South Africa}
\confpin{Dasypus novemcintus}{South America}
\confpin{Rhinocerus sondaicus}{Java}
\confpin{Canis lupus}{Northern sphere}
\confpin{Ramphastus spec.}{South Amerika}
\confpin{Panthera tigris sondaica}{Java}
\confpin{Hippocampus spec.}{the ocean}
\confpin{Anthonomus grandis}{Mexico}
\confpin{Petrogale penicillata}{Australia}
\confpin{Tarsius spec.}{Sumatra}
\end{document}


The result is as follows:

\usepackage[freepin,boxed]{ticket}


in the preamble. For the other options, see the manual.

To create confpin content, you can use the following command in Excel and copy the content to your document. It assumes that column A has name surname, and column B has affiliation.

=CONCATENATE("\confpin{"; A2; "}{";B2; "}")

-
I met this package while looking for a solution and really liked it. So, I decided to put it here as an answer to my own question. – petrichor Jan 20 '13 at 17:09

The file informations.csv (the first line is for variable names)

"name","sirname","university"
"Aaaa","Bbbb","Cccc"


The file foo.tex (format according to your preferences)

\documentclass[12pt,a5paper,landscape]{article}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% If the error
% No room for ..''
% increase the reserved inserts
%--------------------------------------------
% \usepackage{etex} % to use etex extensions
% \reserveinserts{28} % using etex extensions

\usepackage[english]{babel}

% UTF-8 support any characters
\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
%\usepackage{ucs}
% Defaul loaded character table is ASCII and latin

\usepackage{amsmath}
\usepackage{amssymb} % amsfonts is part of amssymb

\usepackage{graphicx}
\usepackage[usenames]{color}
%\usepackage{chancery} % change serif to Zapf Chancery
\usepackage{datatool}
\usepackage[lmargin=1cm,tmargin=1cm,bmargin=1.6cm,rmargin=1.6cm]{geometry}
\usepackage{fancybox} % border page and boxes
\usepackage{mathpazo}

\sloppy

\pagestyle{empty}

% box around pages, using fancybox package
%
% \fancypage{\fbox}{}

\fancypage{\setlength{\fboxsep}{8pt}\doublebox}{}

\newcommand{\event}{Insert the title of event here}

\begin{document}
% default separator is coma and default delimiter is double quote
% \DTLsetseparator{,}
% \DTLsetdelimiter{"}

\DTLforeach{list}{%
\firstname=name,\sirname=sirname,\university=university}{%

\fontfamily{pbk}\fontseries{m}\fontshape{n}\selectfont
\baselineskip 2.5em

\vspace*{2cm}

\begin{center}
{\Large \firstname~\MakeUppercase{\sirname}}

\vskip 2cm

{\large \university}

\vfill

\hrulefill

\event~\fbox{logo here}
\end{center}

\newpage
}
\end{document}


Here is the output:

-
I created a file with the content wou gave but I got many errors: Missing \endcsname inserted: \DTLloaddb{list}{informations.csv}", Missing { inserted: \DTLloaddb{list}{informations.csv}, Package datatool Error: Can't assign \firstname : there is no key name' in data base list': }. – petrichor Jan 20 '13 at 15:49
And actually I would like to get many badges in an A4 page. Not getting a badge per page. – petrichor Jan 20 '13 at 15:50
I believe that the easiest way is to print more than one page, changing the printer options. My sample create one page for each line on csv file. You can change the page size using geometry (see the code) and then you print 4 or 8 pages per sheet. – Sigur Jan 20 '13 at 15:52
Your csv file looks like mine? Does it have the same variables defined? Did you save it on the same folder as your tex file? – Sigur Jan 20 '13 at 15:55
Yes, I've created it in the same folder with the same name and content. – petrichor Jan 20 '13 at 16:00

A slight variation from Sigur's answer, building on his code:

\documentclass{article}
\usepackage{pdfpages}
\usepackage[a4paper,margin=.5in]{geometry}
\usepackage{filecontents}
\begin{filecontents*}{informations.csv}
name,sirname,university
Jon,Doe,From Moon
Jane,Dipp,From Mars
Jon,Doe,From Moon
Jane,Dipp,From Mars
Jon,Doe,From Moon
Jane,Dipp,From Mars
Jon,Doe,From Moon
Jane,Dipp,From Mars
Jon,Doe,From Moon
Jane,Dipp,From Mars
\end{filecontents*}
\begin{filecontents*}{cards.tex}
\documentclass[12pt,a5paper,landscape]{article}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{datatool}
\usepackage[lmargin=1cm,tmargin=1cm,bmargin=1.6cm,rmargin=1.6cm]{geometry}
\usepackage{fancybox} % border page and boxes
\usepackage{mathpazo}
\sloppy
\pagestyle{empty}
\fancypage{\setlength{\fboxsep}{8pt}\doublebox}{}
\newcommand{\event}{Univeristy Name \\

\begin{document}

\DTLforeach{list}{%
\firstname=name,\sirname=sirname,\university=university}{%
\fontfamily{pbk}\fontseries{m}\fontshape{n}\selectfont
\baselineskip 2.5em
\vspace*{2cm}
\begin{center}
{\Large \firstname~\MakeUppercase{\sirname}}
\vskip 2cm
{\large \university}
\vfill

\hrulefill

\parbox[b]{.7\textwidth}{\event}\hfill\fbox{\includegraphics[width=2cm]{example-image-a}}
\end{center}
\newpage
}%
\end{document}
\end{filecontents*}
%
% compile with pdflatex
\immediate\write18{pdflatex cards.tex}
%
\begin{document}
\includepdf[pages=-,nup=2x4,delta=0.0in 0cm,turn=true,frame=true]{cards.pdf}
\end{document}


-
Please, how to use your code? Should I save it on a tex file? What to do with \immediate\write18{pdflatex cards.tex}? – Sigur Jan 20 '13 at 16:15
@Sigur Just save the code as somefile.tex and pdflatex somefile.tex. – Harish Kumar Jan 20 '13 at 16:17
I got ! Package pdfpages Error: Cannot find file cards.pdf'. – Sigur Jan 20 '13 at 16:30
@Sigur cards.pdf will be created in the same folder (unless you have some mechanism to move it elsewhere) as the somefile.tex. Just look at it. – Harish Kumar Jan 20 '13 at 16:32
Sorry, I didn't note the \inclugraphics. I have to change it. – Sigur Jan 20 '13 at 16:41

Here's a simple solution using pstricks

\documentclass{article}
\usepackage{pstricks}%..% to create card and position tags/labels
\usepackage{datatool}%..% for managing source for names and affiliations
\usepackage[margin=0.5in]{geometry}
%% command to handle the event name and related matter.
\newcommand{\eventname}{\begin{minipage}[c]{2.5in}\raggedright{}%
Name of Event \\
\end{minipage}}
%% in case you want some white space for when cutting the cards:  otherwise set both to zero.
\newlength{\cardhsep}\setlength{\cardhsep}{2pt}%..% horizontal space between cards
\newlength{\cardvsep}\setlength{\cardvsep}{2pt}%..% vertical space between rows of cards
\newcounter{cntnamecard}                       %..% counter to keep track of namecard and facilitate making "paragraphs"
\psset{unit=0.25in}                            %..% or you can set "xunit=..." and "yunit=..." change dimensions of card
\newcommand{\namecard}[3]{%
\begin{pspicture}(0,0)(14,8)
\rput(7,6){\Large{}\textbf{\sffamily{}#1}}%..% node for name
\rput(7,5){#2}                            %..% node for affiliation
\psline(0.25,1.75)(13.75,1.75)
\rput[l](0.25,1){#3}                      %..% node for event name
\rput[r](13.75,1){\includegraphics[height=0.33in]{example-image-a}}%..% logo
\pspolygon(0,0)(14,0)(14,8)(0,8)
\end{pspicture}\hspace*{\cardhsep}%
\ifodd\thecntnamecard\par\fi%..% automate when "paragraphs" are set.
\stepcounter{cntnamecard}}
%%
\setlength{\parindent}{0pt}%..% no need for indentation.
\setlength{\parskip}{\dimexpr-\lineskip+\cardvsep\relax}
\renewcommand{\thepage}{}
\begin{document}

\DTLforeach{namecard}{\firstname=first,
\lastname=last,
\school=affiliation,
\characterization=characterization}
{\namecard{\firstname{} \lastname}
{\school}
{\eventname}}

\end{document}


where the cvs file looks something like:

"first","last","affiliation","characterization"
`