3

I would like to print initial account data for individual students and place 8 cards on a physical page. This is my MWE.

\documentclass[fontsize=12pt, paper=a7, paper=landscape, parskip=half]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{lmodern}
\usepackage[ngerman]{babel}

\usepackage{geometry}
\usepackage{pgfpages}
\usepackage{csvsimple}
\usepackage{filecontents}


% Creates a card
\newcommand{\Card}[5]%
{%
  \begin{flushleft}
  \textbf{Zugangsdaten}
  \medskip\par
  \begin{tabular}{@{}ll@{}}
  Klasse:       & \textbf{#1} \\[.7ex]        
  Name:         & \textbf{#2} \\[.7ex]
  Vorname:      & \textbf{#3} \\[.7ex]
  Benutzername: & \texttt{#4} \\[.7ex] 
  Password:     & \texttt{#5} 
  \end{tabular}
  \end{flushleft}
  \clearpage
}

% Layout of logical pages
\geometry{margin = 13mm}
\pagestyle{empty}

% Shipping-out configuration
\pgfpagesuselayout{8 on 1}[a4paper]


\begin{document}

% Example data
\begin{filecontents*}{accounts.csv}
Klasse,Stufe,Vorname,Nachname,Benutzername,Passwort
5a,5,Vorname01,Name01,test01,pwd01
5a,5,Vorname02,Name02,test02,pwd02
5a,5,Vorname03,Name03,test03,pwd03
5b,5,Vorname04,Name04,test04,pwd04
5b,5,Vorname05,Name05,test05,pwd05
5b,5,Vorname06,Name06,test06,pwd06
5b,5,Vorname07,Name07,test07,pwd07
5c,5,Vorname08,Name08,test08,pwd08
5c,5,Vorname09,Name09,test09,pwd09
5c,5,Vorname10,Name10,test10,pwd10
5c,5,Vorname11,Name11,test11,pwd11
5d,5,Vorname12,Name12,test12,pwd12
\end{filecontents*}

\csvreader[head to column names = true]{accounts.csv}{}%
  {\Card{\Klasse}{\Nachname}{\Vorname}{\Benutzername}{\Passwort}}

\end{document}

However, I need to start a new physical page for each new course (Klasse). In the example above there needs to be a physical page for 5a, 5b etc. Please note that there can be more than 8 students per course.

1

As far as I know, you cannot tell pgfpages to insert a physical page break. So, I think it would be better to use minipages (placing two of them next to each other) instead.

In order to insert a page break, you can compare the last “Klasse” with the current one. If both are not equal, \clearpage is inserted.

You may want to adjust the margins, column gap and positioning of the cards.

\documentclass[fontsize=12pt, paper=a4, parskip=half]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{lmodern}
\usepackage[ngerman]{babel}

\usepackage{geometry}
\usepackage{csvsimple}
\usepackage{filecontents}

% Creates a card
\edef\prevKlasse{}
\edef\currKlasse{}
\newcommand{\Card}[5]%
{%
  \xdef\currKlasse{#1}
  \ifx\currKlasse\prevKlasse\else\clearpage\fi
  \begin{minipage}[t][65mm][t]{95mm}
  \begin{flushleft}
  \textbf{Zugangsdaten}
  \medskip\par
  \begin{tabular}{@{}ll@{}}
  Klasse:       & \textbf{#1} \\[.7ex]        
  Name:         & \textbf{#2} \\[.7ex]
  Vorname:      & \textbf{#3} \\[.7ex]
  Benutzername: & \texttt{#4} \\[.7ex] 
  Passwort:     & \texttt{#5} 
  \end{tabular}
  \end{flushleft}
  \end{minipage}
  \xdef\prevKlasse{#1}
}

% Layout of logical pages
\geometry{margin = 13mm}
\pagestyle{empty}

\begin{document}

% Example data
\begin{filecontents*}{accounts.csv}
Klasse,Stufe,Vorname,Nachname,Benutzername,Passwort
5a,5,Vorname01,Name01,test01,pwd01
5a,5,Vorname02,Name02,test02,pwd02
5a,5,Vorname03,Name03,test03,pwd03
5b,5,Vorname04,Name04,test04,pwd04
5b,5,Vorname05,Name05,test05,pwd05
5b,5,Vorname06,Name06,test06,pwd06
5b,5,Vorname07,Name07,test07,pwd07
5c,5,Vorname08,Name08,test08,pwd08
5c,5,Vorname09,Name09,test09,pwd09
5c,5,Vorname10,Name10,test10,pwd10
5c,5,Vorname11,Name11,test11,pwd11
5d,5,Vorname12,Name12,test12,pwd12
\end{filecontents*}

\csvreader[head to column names = true]{accounts.csv}{}%
  {\Card{\Klasse}{\Nachname}{\Vorname}{\Benutzername}{\Passwort}}

\end{document}
1

Based on the accepted answer by Jasper Habicht I came up with the following alternative. It may not be as elegant as the original version. It has the advantage, however, of precisely positioning the logical pages without cumbersome calculations.

\documentclass[fontsize=12pt, paper=a7, paper=landscape]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{lmodern}
\usepackage[ngerman]{babel}

\usepackage{geometry}
\usepackage{csvsimple}
\usepackage{pgfpages}
\usepackage{multido}
\usepackage{intcalc}
\usepackage{filecontents}

% Creates a card

\edef\prevCourse{}
\edef\currCourse{}
\edef\numStudents{0}

\newcommand{\Card}[5]%
{%
   \xdef\currCourse{#1}
   \ifx\currCourse\prevCourse
     \xdef\numStudents{\intcalcInc{\numStudents}}
   \else
     \multido{}
       {\intcalcMod{\intcalcSub{8}{\intcalcMod{\numStudents}{8}}}{8}}
       {\mbox{}\clearpage}
     \xdef\numStudents{1}
   \fi
   \begin{flushleft}
   \renewcommand{\arraystretch}{1.3}
   \minisec{Zugangsdaten}
   \medskip
   \begin{tabular}{@{}ll@{}}
   Klasse:       & \textbf{#1} \\
   Name:         & \textbf{#2} \\
   Vorname:      & \textbf{#3} \\
   Benutzername: & \texttt{#4} \\
   Passwort:     & \texttt{#5} 
   \end{tabular}
   \end{flushleft}
   \clearpage
   \xdef\prevCourse{#1}
}

% Logical pages
\geometry{margin=13mm}
\pagestyle{empty}

% Shipping-out configuration
\pgfpagesuselayout{8 on 1}[a4paper]


\begin{document}

% Example data
\begin{filecontents*}{accounts.csv}
Klasse,Stufe,Vorname,Nachname,Benutzername,Passwort
5a,5,Vorname01,Name01,test01,pwd01
5a,5,Vorname02,Name02,test02,pwd02
5a,5,Vorname03,Name03,test03,pwd03
5b,5,Vorname04,Name04,test04,pwd04
5b,5,Vorname05,Name05,test05,pwd05
5b,5,Vorname06,Name06,test06,pwd06
5b,5,Vorname07,Name07,test07,pwd07
5c,5,Vorname08,Name08,test08,pwd08
5c,5,Vorname09,Name09,test09,pwd09
5c,5,Vorname10,Name10,test10,pwd10
5c,5,Vorname11,Name11,test11,pwd11
5d,5,Vorname12,Name12,test12,pwd12
\end{filecontents*}

\csvreader[head to column names = true]{accounts.csv}{}%
  {\Card{\Klasse}{\Nachname}{\Vorname}{\Benutzername}{\Passwort}}

\end{document}

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.