新命令 dynTable 在子文件中不起作用

新命令 dynTable 在子文件中不起作用

我正在尝试在 Overleaf 中编写考试。我正在使用子文件,因此我有一个包含一堆子文件的 MainFile.tex 结构。这一直运行良好。当我想添加一个将显示多项选择答题纸的最终页面时,我遇到了一个问题。此页面包含一个 /newcommand(我在 stackexchange 上找到的代码)。当我编译单个页面时,新命令运行良好 - 我得到以下内容:在此处输入图片描述

然而当我尝试重新编译主页时出现错误

在此处输入图片描述

我的代码是:

\documentclass[a4paper,12pt,addpoints]{exam} 
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage{anyfontsize}
\usepackage[margin=2.5cm]{geometry}
\usepackage{multicol}
\usepackage{array}
\parindent 0em     % no indenting on para
% \printanswers


\usepackage{subfiles}
\newcommand{\tabitem}{~~\llap{\textbullet}~~}

\begin{document} 

% font family for entire document
% \sffamily      
% \subfile{./sections/title}              % PRINT THE TITLE PAGE
% \pagebreak
% \subfile{./sections/multipleChoice}     % PRINT THE MULTIPLE CHOICE PART
\pagebreak
%\subfile[sections/longanswer.tex]

% \subfile{./sections/longQuestionsSetup.tex}     % get setup for the long question format
% %this rule formats the long question Question line
% \qformat{\parbox{\textwidth}{Question \thequestion{} (\totalpoints{} marks) \hfill  \vspace*{0.5cm}}}


%\subfile{./sections/headerPage}

% \subfile{./sections/multiplechoice} \newpage %\subfile{./sections/longAnswer} % 现在生成长答案部分

\pagebreak

\subfile{./sections/multiChoiceTearoff}

\pagebreak
\vspace{3cm}
\large 
\center
\textbf{End of Exam}

\pagebreak

\newpage
\end{document}

\documentclass[../main.tex]{subfiles}
\usepackage{array}
\usepackage[a4paper]{geometry}
\baselineskip=10mm
\parskip=0pt
\makeatletter
\newcommand*{\InitToks}{\toks@={}}
\newcommand{\AddToks}[1]{\toks@=\expandafter{\the\toks@ #1}}
\newcommand*{\PrintToks}{\the\toks@}
\unitlength=1mm
\def\BOX{\framebox(7 ,7){}}
\newcount\rowNo

\newcommand*{\dynTable}[1]{%
  \begingroup
    \InitToks
    \AddToks{\tabcolsep=0pt\begin{tabular}{c*{5}{>{\centering}p{10mm}}}}%
    \AddToks{&&A&B&C&D \tabularnewline}
    \vspace{1cm}
    \rowNo=0 %
    \loop\ifnum\rowNo<#1\relax
      \advance\rowNo by 1
      \AddToks{\strobe & }
      \expandafter\AddToks\expandafter{%
         \the\rowNo & 
         \BOX & \BOX & \BOX & \BOX %& \BOX & \BOX & \BOX & \BOX & \BOX & \BOX%
        \tabularnewline}%
    \repeat
   \AddToks{\end{tabular}}%
    \PrintToks
  \endgroup}
\makeatother

\def\strobe{\rule{0pt}{4mm}\rule{3mm}{2.54mm}}

\begin{document}
\begin{minipage}{7cm}
    \raggedright
    \Large{\textbf{Student Number}}
    %\large{\Student Number}\\
    \huge
    \begin{tabular}{| p{0.5cm} | p{0.5cm} | p{0.5cm} | p{0.5cm} | p{0.5cm} | p{0.5cm} | p{0.5cm} | p{0.5cm} | p{0.5cm} |}
        \hline
         & & & & & & & & \\
        \hline
    \end{tabular}
\end{minipage}

\vspace{1cm}
\sffamily\Large

 \textbf{My subject name}
 
 \textbf{Assessment Task - 2023}
 
\textbf{Answer Sheet}

\bigskip
\textbf{Section I - Multiple Choice}

\bigskip
Tick the letter that corresponds to the correct answer. If you make a change clearly indicate which answer is correct.


\dynTable{10}


\end{document}

相关内容