自动生成出席名单

自动生成出席名单

我正在尝试为我的班级生成出勤表。我需要出勤表包含两个内容:1)班级学生名单,其中有一个空白处供他们签名。2)名单的随机版本,这样当我要求学生回答家庭作业问题时,每节课的顺序都会有所不同。

我正在努力解决乳胶中的循环、tabular环境内的列表操作(禁忌)以及所有相关的扩展和全局变量问题。

在下面的 MWE 中,我尝试执行上面的 #1。我可以输入空白行,这不是问题。问题在于在表格中生成学生列表。

任何回答 #2 的人都会得到额外的积分,尽管我已经看到过建议回答这个问题的帖子(请参阅“生成不重复的随机数”以了解我将以它为基础的代码)。

梅威瑟:

\documentclass[12pt]{article}

\usepackage{tabu}                  % Table control
\usepackage{etoolbox}              % csdef
\usepackage{pgffor}

\pagestyle{plain}

\newcounter{studentcounter}

\newcommand\addstudent[1]{%
   \stepcounter{studentcounter}
   \expandafter\def\csname studentlist\thestudentcounter\endcsname{#1}
}

\newcommand\getstudent[1]{%
   \csname studentlist#1\endcsname
}

\addstudent{Donna}
\addstudent{Michael}
\addstudent{Chris}

\begin{document}

\newcommand\finallist{}
\foreach \n in {0,...,\thestudentcounter}{
   \appto\finallist{ \getstudent{\n} \\ }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55

STUDENT 2: \getstudent{2} \\  % This just shows me my macro is working.

\centering{\textbf{\large Attendance}}

\vfil

\sffamily

\taburulecolor{blue}
\arrayrulewidth=2pt
\begin{tabu}{l@{\rule{0pt}{20pt}}}
\multicolumn{1}{l}{Student}\\
\finallist
\rule{2in}{1pt}\\
\rule{2in}{1pt}\\
\rule{2in}{1pt}\\
\end{tabu}

\vfil

\end{document}

编辑/更新:

感谢发布答案的人。根据发布的解决方案,以下是我目前所拥有的记录。我采用了 MWE 并添加了其余上下文,以便人们可以看到最终产品。

\documentclass[11pt]{article}

\usepackage{tabu}                  % Table control
\usepackage{etoolbox}              % csdef
\usepackage{fancyhdr}              % Fancy headings
\usepackage{datenumber}            % Day from Date.
\usepackage{ifthen}
\usepackage{tikz}                  % random

% An environment for changing the left and right margins
% for a block of text.  A typical usage is
% \begin{changemargin}{-0.5cm}{-0.5cm}
\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}

\newcommand{\myline}{\rule{1in}{1pt}}
\newcommand{\mybox}{\fbox{\rule{0pt}{10pt}\quad }}

\setlength{\topmargin}{-0.5in}
\setlength{\textheight}{9.0in}
\setlength{\oddsidemargin}{0in}
\setlength{\textwidth}{6.5in}
\setlength{\headheight}{15pt}
\setlength{\parindent}{0pt}
\setlength{\parskip}{10pt}
\setlength{\headsep}{10pt}
\setlength{\marginparsep}{0.1in}
\setlength{\marginparwidth}{0.5in}

\pagestyle{fancy}

% In the final version, the date will be passed in on the
% command line.
\setdate{2013}{05}{24}

\lhead{\textbf{Math 132: Geometry}}
\rhead{\textbf{Donham}}
\lfoot{}
\cfoot{\textbf{\datedayname, \datedate}}
\rfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

\newcounter{index}
\newcounter{studentcounter}

\newcommand\addstudent[1]{%
   \stepcounter{studentcounter}
   \expandafter\def\csname studentlist\thestudentcounter\endcsname{#1}
}

\newcommand\getstudent[1]{%
   \csname studentlist#1\endcsname
}

% The student list would normally be in a separate file so
% that multiple classes are supported.
\addstudent{Abigail}
\addstudent{Aiden}
\addstudent{Alexander}
\addstudent{Ava}
\addstudent{Daniel}
\addstudent{Emily}
\addstudent{Emma}
\addstudent{Ethan}
\addstudent{Isabella}
\addstudent{Jacob}
\addstudent{Jayden}
\addstudent{Madison}
\addstudent{Mason}
\addstudent{Mia}
\addstudent{Michael}
\addstudent{Noah}
\addstudent{Olivia}
\addstudent{Sophia}
\addstudent{William}

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
\vspace*{1pt}
{\centering \textbf{ \large Attendance } \par}

Students must sign in to receive credit for attending class.  If your
name is in the list below, simply write your initials on the
associated line.  If your name is \textit{not} listed, it means that
you may not be registered for this class!  Print your name on a blank
line, and then write your initials.  You should check with the
registrar to be sure you are registered.

\begin{center}
\sffamily
\setcounter{index}{0}%
\taburulecolor{blue}
\arrayrulewidth=2pt
\begin{tabu}{l@{\rule{0pt}{18pt}\hspace*{0.5in}\myline \quad \mybox \quad \mybox}}
\multicolumn{1}{l}{Student \hfill Initials \qquad HW \quad P}\\ \hline
\whiledo{\value{index} < \value{studentcounter}}{%
  \addtocounter{index}{1}%
  \makebox[1in]{\csname studentlist\arabic{index}\endcsname\hfill}\\%
%  \rule{2in}{1pt}\\%
}
\rule{2.5in}{1pt}\\
\rule{2.5in}{1pt}\\
\end{tabu}
\end{center}

\vfill
\pagebreak

% This page has a random list on names to call on students when
% surveying the class (e.g. answers to the day's homework problems.
\makeatletter
\def\declarenumlist#1#2#3{%
\expandafter\edef\csname pgfmath@randomlist@#1\endcsname{#3}%
\count@\@ne
\loop
\expandafter\edef
\csname pgfmath@randomlist@#1@\the\count@\endcsname
  {\the\count@}
\ifnum\count@<#3\relax
\advance\count@\@ne
\repeat}

\declarenumlist{mylist}{1}{\value{studentcounter}}

\def\prunelist#1{%
\expandafter\edef\csname pgfmath@randomlist@#1\endcsname
    {\the\numexpr\csname pgfmath@randomlist@#1\endcsname-1\relax}
\count@\pgfmath@randomtemp
\loop
\expandafter\let
\csname pgfmath@randomlist@#1@\the\count@\expandafter\endcsname
\csname pgfmath@randomlist@#1@\the\numexpr\count@+1\relax\endcsname
\ifnum\count@<\csname pgfmath@randomlist@#1\endcsname\relax
\advance\count@\@ne
\repeat}

\vspace*{10pt}
{\centering\textbf{\large Random Student List for \datedayname, \datedate}\par}

\begin{changemargin}{2in}{0in}
\setcounter{index}{0}%
\whiledo{\value{index} < \value{studentcounter}}{%
  \addtocounter{index}{1}%
  \pgfmathrandomitem\z{mylist}
  \getstudent{\z}\\[5pt]
  \prunelist{mylist}
}
\end{changemargin}
\vfill

\end{document}

这是当前的结果... 第0页

以及随机页面... 第1页

答案1

这将在 s 之前插入名称\rule,但不会随机化它们。如果这不是您想要的,请告诉我。我不确定我是否完全理解了您的问题。

\documentclass[12pt]{article}

\usepackage{tabu}                  % Table control
\usepackage{etoolbox}              % csdef
\usepackage{pgffor}
\usepackage{ifthen}

\pagestyle{plain}

\newcounter{studentcounter}

\newcommand\addstudent[1]{%
   \stepcounter{studentcounter}
   \expandafter\def\csname studentlist\thestudentcounter\endcsname{#1}
}

\newcommand\getstudent[1]{%
   \csname studentlist#1\endcsname
}

\addstudent{Donna}
\addstudent{Michael}
\addstudent{Chris}

\newcounter{index}

\begin{document}

\newcommand\finallist{}
\foreach \n in {0,...,\thestudentcounter}{
   \appto\finallist{ \getstudent{\n} \\ }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55

STUDENT 2: \getstudent{2} \\  % This just shows me my macro is working.

\centering{\textbf{\large Attendance}}

\vfil

\sffamily

\taburulecolor{blue}
\arrayrulewidth=2pt
\begin{tabu}{l@{\rule{0pt}{20pt}}}
\multicolumn{1}{l}{Student}\\
\finallist
\setcounter{index}{0}%
\whiledo{\value{index} < \value{studentcounter}}{%
  \addtocounter{index}{1}%
  \makebox[1in]{\csname studentlist\arabic{index}\endcsname\hfill}%
  \rule{2in}{1pt}\\%
}
\end{tabu}

\vfil

\end{document}

答案2

可能需要清理,但它按规范工作。我不声称拥有任何类似 PGF 的专业知识。参考文献这里这里

\documentclass{article}
\usepackage{tikz}

\makeatletter
\def\pgfmathdeclarelist#1#2{%
    \def\pgfmath@list@name{#1}%
    \c@pgfmath@counta=0%
    \pgfmath@declarelistlist#2{\pgfmath@stop}%
}%
\def\pgfmath@declarelistlist#1{%
    \ifx#1\pgfmath@stop%
        \expandafter\edef\csname pgfmath@list@\pgfmath@list@name
@length\endcsname{\the\c@pgfmath@counta}%
    \else%
        \advance\c@pgfmath@counta by1\relax%
        \pgfutil@namedef{pgfmath@list@\pgfmath@list@name @\the\c@pgfmath@counta}{#1}%
        \expandafter\pgfmath@declarelistlist%
    \fi%
}

\def\pgfmathgetlistitem#1#2#3{\expandafter\let\expandafter#1\expandafter=\csname
pgfmath@list@#2@#3\endcsname}

\def\pgfmathsetlistitem#1#2#3{%
    \pgfutil@namedef{pgfmath@list@#1@#2}{#3}%
}

\def\pgfmathgetlistlength#1#2{%
    \expandafter\let\expandafter#1\expandafter=\csname
pgfmath@list@#2@length\endcsname%
}

\def\pgfmathknuthshuffle#1{%
    \pgfmathgetlistlength\pgfmath@len{#1}%
    \pgfmathloop%
    \ifnum\pgfmathcounter>\pgfmath@len%
    \else%
        \pgfmathrandominteger\pgfmath@temp{1}{\pgfmath@len}%
        \pgfmathgetlistitem\pgfmath@@temp{#1}{\pgfmathcounter}%
        \pgfmathgetlistitem\pgfmath@@@temp{#1}{\pgfmath@temp}%
        \def\pgfmath@marshal{\pgfmathsetlistitem{#1}}%
        \expandafter\pgfmath@marshal\expandafter{\expandafter\pgfmath@temp\expandafter}\expandafter{\pgfmath@@temp}%
        \expandafter\pgfmath@marshal\expandafter{\expandafter\pgfmathcounter\expandafter}\expandafter{\pgfmath@@@temp}%
    \repeatpgfmathloop%
}

\makeatother

\begin{document}

\section{Original}

\pgfmathdeclarelist{mylist}{%
{Student A}%
{Student B}%
{Student C}%
{Student D}%
{Student E}%
{Student F}%
{Student G}%
{Student H}%
{Student I}%
{Student J}%
{Student K}%
{Student L}%
{Student M}%
}
\pgfmathgetlistlength{\l}{mylist}

\begin{enumerate}
\foreach \i in {1,...,\l}{
    \pgfmathgetlistitem{\x}{mylist}{\i}
    \item {\x}  \hrulefill \par
}
\end{enumerate}

\section{Shuffling}

\pgfmathknuthshuffle{mylist}

\begin{itemize}
\foreach \i in {1,...,\l}{
    \pgfmathgetlistitem{\x}{mylist}{\i}
    \item {\x}
}
\end{itemize}

\end{document}

在此处输入图片描述

相关内容