使用 csvsimple 和 pgfpages 时的物理分页符

使用 csvsimple 和 pgfpages 时的物理分页符

我想打印每个学生的初始帐户数据,并在一个物理页面上放置 8 张卡片。这是我的 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}

但是,我需要为每门新课程 (Klasse) 创建一个新物理页面。在上面的示例中,需要为 等创建一个物理页面。5a5b注意,每门课程可以有超过 8 名学生。

答案1

据我所知,您无法告诉pgfpages插入物理分页符。因此,我认为最好使用minipages(将两个分页符放在一起)。

为了插入分页符,您可以将最后一个“Klasse”与当前“Klasse”进行比较。如果两者不相等,则\clearpage插入。

您可能需要调整卡片的边距、列间距和定位。

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

答案2

根据接受的答案经过贾斯珀·哈比希特我想到了以下替代方案。它可能不如原始版本那么优雅。但它的优点是可以精确定位逻辑页面,而无需进行繁琐的计算。

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

相关内容