我想生成一个包含多个考试的 PDF 文件(模板可用下面)。
每场考试都必须有“姓名”字段(参见模板),其中填写从外部列表文件(例如 .csv)中获取的学生姓名。
模板:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[top=6mm,includehead,left=1.5cm,bottom=2cm,right=1.5cm,headsep=0.5cm]{geometry}
\usepackage{tikz}
\usepackage{multicol}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{lipsum}
\renewcommand{\footrulewidth}{1.2pt} % linha no footer
\renewcommand{\headrulewidth}{1.2pt}% linha no header
\lfoot{\ttfamily \today}
\rfoot{\ttfamily 14 de dezembro de 2018}
\pagestyle{fancy}
\fancypagestyle{firststyle}{%
\renewcommand{\headrulewidth}{0pt}% Remove header rule
\lhead{%
\def\scale{0.6}%
\def\roundc{\scale*0.1cm}% rc = 10% de sc
\raisebox{-2\baselineskip}[0pt][0pt]{\begin{tikzpicture}[scale=\scale]
\definecolor{tempcolor}{RGB}{200,25,30}
\filldraw[tempcolor][rounded corners=\roundc] (2cm,0cm) rectangle (1.2cm,-0.5cm);
\filldraw[tempcolor][rounded corners=\roundc] (2cm,-0.6cm) rectangle (1.1cm,-1.1cm);
\filldraw[tempcolor][rounded corners=\roundc] (2cm,-0.6cm) rectangle (1.5cm,-1.1cm);
\filldraw[tempcolor][rounded corners=\roundc] (1.7cm,-1.2cm) rectangle (1.2cm,-1.7cm);
\filldraw[tempcolor][rounded corners=\roundc] (0.6cm,-1.2cm) rectangle (1.1cm,-1.7cm);
\filldraw[tempcolor][rounded corners=\roundc] (1.6cm,-1.2cm) rectangle (1.8cm,-1.7cm);
\filldraw[tempcolor][rounded corners=\roundc] (1.7cm,-1.8cm) rectangle (1.2cm,-2.3cm);
\node[scale=\scale,fill=white] at (5.92,-0.85) {\resizebox{6.7cm}{0.5cm}{\sffamily \textbf{ESCOLA}}};
\node[scale=\scale,fill=white] at (4.52,-1.55) {\resizebox{5cm}{0.5cm}{\sffamily {Construindo o Futuro}}};
\end{tikzpicture}}
}
\chead{\raisebox{-2\baselineskip}[0pt][0pt]{\rule[-2.5\baselineskip]{\linewidth}{1.2pt}}}
\rhead{\raisebox{-2\baselineskip}[0pt][0pt]{\begin{tabular}{@{}r@{}}
\tikz \node at (0,0) {\textbf{Final Exam}};\\
\tikz[baseline]{\node[anchor=base, draw=black, thick, minimum width=8.5cm, minimum height=7mm,rounded corners, yshift=-2mm,label={[fill=white,label distance=-2mm,inner xsep=2pt]90:{\ttfamily Name}:}] {\phantom{\ttfamily 15,0}};}
\tikz[baseline]{\node[anchor=base, draw=black, thick, minimum width=2cm, minimum height=7mm,rounded corners, yshift=-2mm,label={[fill=white,label distance=-2mm,inner xsep=2pt]90:{\ttfamily Turma}:}] {\phantom{\ttfamily 15,0}};}
\tikz[baseline]{\node[anchor=base, draw=black, thick, minimum width=1.5cm, minimum height=7mm,rounded corners, yshift=-2mm,label={[fill=white,label distance=-2mm,inner xsep=2pt]90:{\ttfamily Valor}:}] {\ttfamily 15,0};}
\tikz[baseline]{\node[anchor=base, draw=black, thick, minimum width=1.5cm, minimum height=7mm,rounded corners, yshift=-2mm,label={[fill=white,label distance=-2mm,inner xsep=2pt]90:{\ttfamily Nota}:}] {\phantom{\ttfamily 15,0}};}
\end{tabular}}
}
\lfoot{\ttfamily Prof. Lucas}
\rfoot{\ttfamily \today}
}
\AtBeginDocument{
\thispagestyle{firststyle}
\vspace*{2\baselineskip}
}
\begin{document}
\begin{multicols}{2}
\begin{enumerate}
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\end{enumerate}
\end{multicols}
\end{document}
答案1
当然,这是可能的。我专注于从 csv 文件读取数据并构建多页文档的循环。目前,我不会更改您的 Ti钾Z 代码,可以简化。无论如何,这会从文件中读取名称并打印“考试”。
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[top=6mm,includehead,left=1.5cm,bottom=2cm,right=1.5cm,headsep=0.5cm]{geometry}
\usepackage{tikz}
\usepackage{multicol}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{lipsum}
\renewcommand{\footrulewidth}{1.2pt} % linha no footer
\renewcommand{\headrulewidth}{1.2pt}% linha no header
\lfoot{\ttfamily \today}
\rfoot{\ttfamily 14 de dezembro de 2018}
\pagestyle{fancy}
\fancypagestyle{firststyle}{%
\renewcommand{\headrulewidth}{0pt}% Remove header rule
\lhead{%
\def\scale{0.6}%
\def\roundc{\scale*0.1cm}% rc = 10% de sc
\raisebox{-2\baselineskip}[0pt][0pt]{\begin{tikzpicture}[scale=\scale]
\definecolor{tempcolor}{RGB}{200,25,30}
\filldraw[tempcolor][rounded corners=\roundc] (2cm,0cm) rectangle (1.2cm,-0.5cm);
\filldraw[tempcolor][rounded corners=\roundc] (2cm,-0.6cm) rectangle (1.1cm,-1.1cm);
\filldraw[tempcolor][rounded corners=\roundc] (2cm,-0.6cm) rectangle (1.5cm,-1.1cm);
\filldraw[tempcolor][rounded corners=\roundc] (1.7cm,-1.2cm) rectangle (1.2cm,-1.7cm);
\filldraw[tempcolor][rounded corners=\roundc] (0.6cm,-1.2cm) rectangle (1.1cm,-1.7cm);
\filldraw[tempcolor][rounded corners=\roundc] (1.6cm,-1.2cm) rectangle (1.8cm,-1.7cm);
\filldraw[tempcolor][rounded corners=\roundc] (1.7cm,-1.8cm) rectangle (1.2cm,-2.3cm);
\node[scale=\scale,fill=white] at (5.92,-0.85) {\resizebox{6.7cm}{0.5cm}{\sffamily \textbf{ESCOLA}}};
\node[scale=\scale,fill=white] at (4.52,-1.55) {\resizebox{5cm}{0.5cm}{\sffamily {Construindo o Futuro}}};
\end{tikzpicture}}
}
\chead{\raisebox{-2\baselineskip}[0pt][0pt]{\rule[-2.5\baselineskip]{\linewidth}{1.2pt}}}
\rhead{\raisebox{-2\baselineskip}[0pt][0pt]{\begin{tabular}{@{}r@{}}
\tikz \node at (0,0) {\textbf{Final Exam}};\\
\tikz[baseline]{\node[anchor=base, draw=black, thick, minimum width=8.5cm,
minimum height=7mm,rounded corners, yshift=-2mm,label={[fill=white,label
distance=-2mm,inner xsep=2pt]90:{\ttfamily Name}:}] {\myname\phantom{\ttfamily 15,0}};}
\tikz[baseline]{\node[anchor=base, draw=black, thick, minimum width=2cm, minimum height=7mm,rounded corners, yshift=-2mm,label={[fill=white,label distance=-2mm,inner xsep=2pt]90:{\ttfamily Turma}:}] {\phantom{\ttfamily 15,0}};}
\tikz[baseline]{\node[anchor=base, draw=black, thick, minimum width=1.5cm, minimum height=7mm,rounded corners, yshift=-2mm,label={[fill=white,label distance=-2mm,inner xsep=2pt]90:{\ttfamily Valor}:}] {\ttfamily 15,0};}
\tikz[baseline]{\node[anchor=base, draw=black, thick, minimum width=1.5cm, minimum height=7mm,rounded corners, yshift=-2mm,label={[fill=white,label distance=-2mm,inner xsep=2pt]90:{\ttfamily Nota}:}] {\phantom{\ttfamily 15,0}};}
\end{tabular}}
}
\lfoot{\ttfamily Prof.\ Lucas}
\rfoot{\ttfamily \today}
}
\AtBeginDocument{
\thispagestyle{firststyle}
\vspace*{2\baselineskip}
}
\usepackage{xstring}
\usepackage{pgfplotstable}
% from https://tex.stackexchange.com/a/445369/121799
\newcommand*{\ReadOutElement}[4]{%
\pgfplotstablegetelem{#2}{#3}\of{#1}%
\let#4\pgfplotsretval
}
\usepackage{filecontents}
\begin{filecontents*}{students.csv}
first last middle
Carla TeX nan
Karl Koala Konrad
TokZ Mouse {Topolino Jerry}
\end{filecontents*}
\begin{document}
\pgfplotstableread{students.csv}\loadedtable
\pgfplotstablegetrowsof{\loadedtable}
\pgfmathtruncatemacro{\rownum}{\pgfplotsretval-1}
\foreach \X in {0,...,\rownum}
{\setcounter{page}{1}
\ReadOutElement{\loadedtable}{\X}{first}{\tmpfirst}
\ReadOutElement{\loadedtable}{\X}{last}{\tmplast}
\ReadOutElement{\loadedtable}{\X}{middle}{\tmpmiddle}
\typeout{\tmpmiddle}
\IfStrEq{\tmpmiddle}{nan}{\xdef\myname{\tmpfirst~\tmplast}}{\xdef\myname{\tmpfirst~\tmpmiddle~\tmplast}}
\thispagestyle{firststyle}
\vspace*{2\baselineskip}
\begin{multicols}{2}
\begin{enumerate}
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\item \lipsum[1]
\end{enumerate}
\end{multicols}
\clearpage
}
\end{document}