
Como professora de holandês, minha escala de notas vai de 1,0 a 10,0. O cálculo da nota depende de três variáveis: o N-termo; a nota do aluno; o número total de pontos do exame.
Gostaria que meus exames gerassem automaticamente uma tabela de notas que consistisse em quatro tabelas separadas, onde cada tabela contém partes específicas da escala de notas: [1,0;3,2] e [3,3;5,4] e [5,5;7,7] e [7,8;10,0].
Com N-term=1,0 e uma pontuação total (incluindo zero pontos) divisível por quatro resultará em quatro mesas do mesmo tamanho. Em muitos outros casos não. Veja o exemplo abaixo.
Este é um exemplo para um termo N de 0,0 e um número total de 47 pontos:
Até agora, tenho um código que faz a maior parte do trabalho. O problema, porém, é que o comprimento de cada tabela separada é determinado manualmente no código. Eu realmente gostaria que isso também acontecesse automaticamente.
Um ex-colega escreveu o código; na maioria das vezes, não tenho certeza de como funciona.
A confecção da tabela funciona com um loop foreach. O \i
valor utilizado refere-se à pontuação do candidato, sendo que o final da tabela depende da nota correspondente a um determinado número de pontos.
Então talvez um \foreach \i in {0,...,\GetNumPoints} \while 1,0 =< \NormFormule =< 3.2
ou algo assim funcione melhor. Mas não tenho ideia de como isso pode ser feito.
Alguma sugestão?
\documentclass[addpoints]{exam}
\usepackage{tikz}
%-----------------------------------------
% The Nterm determines which grade correspends to which grade; this is normally a number between 0,0 and 2,0
%-----------------------------------------
\newcommand{\Nterm}{1.0}
%-----------------------------------------
% 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{
\ifdim \Nterm pt < 1 pt
max(
9 * ( #1 / \GetNumPoints ) + \Nterm ,
1 + ( #1 * ( 9 / \GetNumPoints ) * 0.5 ),
10 - ( \GetNumPoints - #1 ) * ( 9 / \GetNumPoints ) * 2
)
\else
min(
9 * ( #1 / \GetNumPoints ) + \Nterm ,
1 + ( #1 * ( 9 / \GetNumPoints ) * 2 ),
10 - ( \GetNumPoints - #1 ) * ( 9 / \GetNumPoints ) * 0.5
)
\fi
}
\pgfmathprintnumber[fixed, precision=1, fixed zerofill, use comma]{\pgfmathresult}}
%-----------------------------------------
% This is the command for making the table; which works fine. Except for needing to manually define the length of the specific tables
%-----------------------------------------
\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}
Responder1
Reescrevi o código completo com a sintaxe expl3, porque acho que é mais fácil de manter no longo prazo. Além disso, as coisas ficaram um pouco mais fáceis dessa maneira. Usei o siunitx
pacote para formatar os números.
Acho que este código é o que você deseja: ele gera quatro colunas com as escalas de notas exigidas. O comprimento das colunas varia dependendo do número de pontos que você pode obter.
\documentclass[addpoints]{exam}
% use siunitx to format numbers
\usepackage{siunitx}
\sisetup{
round-mode = places,
round-precision = 1,
output-decimal-marker = {,}
}
\ExplSyntaxOn
% variable that stores the amount of exam points
\fp_new:N \g_kenadams_exampoints_exampoints_fp
\fp_gset:Nn \g_kenadams_exampoints_exampoints_fp { 1.0 }
% variable that stores the nterm
\fp_new:N \g_kenadams_exampoints_nterm_fp
\fp_gset:Nn \g_kenadams_exampoints_nterm_fp { 1.0 }
% command to change the nterm
\NewDocumentCommand{\SetPointsNterm}{ m }{
\fp_gset:Nn \g_kenadams_exampoints_nterm_fp { #1 }
}
\makeatletter
% internal command to retrieve the current amount of exam points
% set by the exam class
\cs_new:Npn \kenadams_exampoints_update: {
\cs_if_exist:cT { exam@numpoints } {
\fp_gset:Nn \g_kenadams_exampoints_exampoints_fp { \exam@numpoints }
}
}
\makeatother
% internal command to calculate a score from a given point value
% the logic is taken over from the original code
\cs_new:Npn \kenadams_exampoints_calculatescore:n #1 {
\fp_eval:n {
round( \g_kenadams_exampoints_nterm_fp < 1 ?
max(
9 * ( #1 / \g_kenadams_exampoints_exampoints_fp ) + \g_kenadams_exampoints_nterm_fp ,
1 + ( #1 * ( 9 / \g_kenadams_exampoints_exampoints_fp ) * 0.5 ),
10 - ( \g_kenadams_exampoints_exampoints_fp - #1 ) * ( 9 / \g_kenadams_exampoints_exampoints_fp ) * 2
)
:
min(
9 * ( #1 / \g_kenadams_exampoints_exampoints_fp ) + \g_kenadams_exampoints_nterm_fp ,
1 + ( #1 * ( 9 / \g_kenadams_exampoints_exampoints_fp ) * 2 ),
10 - ( \g_kenadams_exampoints_exampoints_fp - #1 ) * ( 9 / \g_kenadams_exampoints_exampoints_fp ) * 0.5
)
, 1 , 1 )
}
}
% internal variable (counter) that stores the current table row
\int_new:N \g_kenadams_exampoints_tablerow_int
% internal command to create a part of the set of tables
\cs_new:Npn \kenadams_exampoints_tablepart:nnn #1 #2 {
% clearing temporary sequence variable
\seq_clear:N \l_tmpa_seq
% stepwise increase table row number as long as
% the calculated score from this value is less than #2
\fp_do_until:nNnn { \kenadams_exampoints_calculatescore:n { \g_kenadams_exampoints_tablerow_int } } > { #2 } {
% add formatted table row to sequence variable
\seq_put_right:Nx \l_tmpa_seq {
\int_use:N \g_kenadams_exampoints_tablerow_int &
\num { \kenadams_exampoints_calculatescore:n { \g_kenadams_exampoints_tablerow_int } }
}
\int_gincr:N \g_kenadams_exampoints_tablerow_int
}
\begin{minipage}[t]{.23\textwidth} \centering (\num{#1}--\num{#2}) \\
\begin{tabular}{ | c | c | }
\hline
\textbf{score} & \textbf{grade} \\ \hline
% insert the values stored in the sequence variable
% and add \\ after each item
\seq_use:Nn \l_tmpa_seq { \\ } \\
\hline
\end{tabular}
\end{minipage}
}
% command to print the grading table
\NewDocumentCommand{\MakePointsTable}{ }{
% retrieve current amount of exam points
\kenadams_exampoints_update:
% reset table row counter
\int_gzero:N \g_kenadams_exampoints_tablerow_int
\bigskip
\Huge Grading ~ Table
\bigskip \par
\normalsize
% typeset the four parts of the grading table
\kenadams_exampoints_tablepart:nnn { 1.0 } { 3.2 }
\kenadams_exampoints_tablepart:nnn { 3.3 } { 5.4 }
\kenadams_exampoints_tablepart:nnn { 5.5 } { 7.7 }
\kenadams_exampoints_tablepart:nnn { 7.8 } { 10.0 }
}
\ExplSyntaxOff
%-----------------------------------------
% The Nterm determines which grade correspends to which grade; this is normally a number between 0,0 and 2,0
%-----------------------------------------
\SetPointsNterm{1.0}
\begin{document}
\begin{questions}
\question[60]
The content of this question is irrelevant.
\end{questions}
\MakePointsTable
\end{document}
Pois \question[47]
você obteria:
Pois \question[47]
e \SetPointsNterm{0.0}
você obteria: