自动生成与考试分数对应的成绩表

自动生成与考试分数对应的成绩表

我想自动添加一个表格,显示与分数对应的等级高度。

到目前为止,我已经

\tcprintroundresult{1}
\tcsetcoltype{|c|c|}{>{\centering\arraybackslash}c|}
\vtablecalc [1]{points}{x=0,1,2,3,4,\numpoints}{grade}{x/\numpoints *9+1}

可以。但我真的希望 x 自动加到总点数。有人有什么建议可以解决这个问题吗?

在此处输入图片描述

另外,如果这张表太长,是否可以自动将其分成更多表?

答案1

感谢一位前同学,我找到了一个解决方案,它满足了我的大部分愿望。说实话,我不知道大部分是如何实现的。但它效果很好。

\documentclass[addpoints]{exam}

\usepackage{tikz}

%-----------------------------------------
% This is some prework that needs to be done
%-----------------------------------------
\makeatletter
   \providecommand{\exam@numpoints}{1}%
   \newcommand{\GetNumPoints}{\exam@numpoints}%
    \newcommand*{\@MyTempTableTokens}{}%
    \newtoks\@tabtoks
    %%% assignments to \@tabtoks must be global, because they are done in \foreach
    \newcommand\AddTableTokens[1]{\global\@tabtoks\expandafter{\the\@tabtoks#1}}
    \newcommand\eAddTableTokens[1]{% 
        \protected@edef\@MyTempTableTokens{#1}%
        \expandafter\AddTableTokens\expandafter{\@MyTempTableTokens}}
    %%% variable should always be operated on either always locally or always globally
    \newcommand*\ResetTableTokens{\global\@tabtoks{}}
    \newcommand*\PrintTableTokens{\the\@tabtoks}
\makeatother
\newcommand*{\NormFormule}[1]{%
    \pgfmathparse{
        9 * ( #1 / \GetNumPoints ) + 1
    }
    \pgfmathprintnumber[fixed, precision=1, fixed zerofill, use comma]{\pgfmathresult}}


%-----------------------------------------
% This is the command for making the table
%-----------------------------------------
\newcommand{\maketable}{\bigskip
\Huge Grading Table\bigskip\\\normalsize
    \ResetTableTokens
    \foreach \i in {0,...,14}   %THIS IS WHERE I GOT STUCK!
    {\eAddTableTokens{\i & \noexpand\NormFormule{\i} \\}}{}                 
        \begin{minipage}[t]{.23\textwidth}\centering$(1{,}0-3{,}2)$\\       
            \begin{tabular}{|c|c|}
                \hline
                \textbf{score}&\textbf{grade}\\\hline\centering
                \PrintTableTokens
                \hline
            \end{tabular}
        \end{minipage}  
    \ResetTableTokens
    \foreach \i in {15,...,29} {\eAddTableTokens{\i & \noexpand\NormFormule{\i} \\}}
        \begin{minipage}[t]{.23\textwidth}\centering$(3{,}3-5{,}4)$\\
            \begin{tabular}{|c|c|}
                \hline
                \textbf{score}&\textbf{grade}\\\hline\centering
                \PrintTableTokens
                \hline
            \end{tabular}
        \end{minipage}          
    \ResetTableTokens
    \foreach \i in {30,...,44} {\eAddTableTokens{\i & \noexpand\NormFormule{\i} \\}}
        \begin{minipage}[t]{.23\textwidth}\centering$(5{,}5-7{,}7)$\\
            \begin{tabular}{|c|c|}
                \hline
                \textbf{score}&\textbf{grade}\\\hline\centering
                \PrintTableTokens
                \hline
            \end{tabular}
        \end{minipage}      
    \ResetTableTokens
    \foreach \i in {45,...,\GetNumPoints} {\eAddTableTokens{\i & \noexpand\NormFormule{\i} \\}}
        \begin{minipage}[t]{.23\textwidth}\centering$(7{,}8-10{,}0)$\\
            \begin{tabular}{|c|c|}
                \hline
                \textbf{score}&\textbf{grade}\\\hline\centering
                \PrintTableTokens
                \hline
            \end{tabular}
        \end{minipage}
}


%-----------------------------------------
% And here the actual exam begins
%-----------------------------------------

\begin{document}

\begin{questions}
    \question[60]
    The content of this question is irrelevant.
\end{questions}

\maketable

\end{document}

相关内容