2

Following the question from here: Exsheets: improve subquestions scores features using tasks. Is it possible to automatically generate a table with the following aspect like:

\documentclass{article}

\usepackage{array}

\begin{document}
\begin{tabular}{|l|l|l|l|l|}
\hline
\multicolumn{2}{|c|}{Question} & \multicolumn{2}{c|}{Points} & Notes \\     \hline
1 & 1.1 & 4 & 1   & \\ \cline{2-2} \cline{4-5}
  & 1.2 &   & 1   & \\ \cline{2-2} \cline{4-5}
  & 1.3 &   & 2   & \\ \hline
2 & 2.1 & 3 & 1.5 & \\ \cline{2-2} \cline{4-5}
  & 2.2 &   & 1.5 & \\ \hline
    \multicolumn{2}{|l|}{Total} & \multicolumn{2}{r|}{7} & \\ \hline
\end{tabular}
\end{document}

The code there for the table almost does that, but I think if there was a way to grab properties from subquestions like it is done for questions it would be easier. I am talking about define two new commands \SubQuestionNumber{#1} and \GetQuestionProperty{subpoints}{#1} (both used inside \ForEachQuestion{}), as such \SubQuestionNumber{#1} would return the number (label?) of subquestions in each question and \GetQuestionProperty{subpoints}{#1} the score for each subquestion.

enter image description here

  • ExSheets does not really know the concept of subquestions like other packages may do. The tasks environment we used in the linked question is just a list link environment which is not tied to exsheets. We could have an enumerate list instead, for instance. – clemens Jun 14 '13 at 18:48
  • Do you really need all those lines? If not then the code from the linked question could easily be adapted... – clemens Jun 14 '13 at 18:49
  • @cgnieder I understand your first comment. But I think that subquestions would be a valuable feature (implemented with tasks or enumitem). Regarding the second comment, I wanted to easily divide what is question from what is points and grades; thus I thought of something like in the picture. But I am very open to new thoughts. I tried to play a little with the code in the linked questions, but hadn't done much since I am not used to LaTeX3 syntax. – cacamailg Jun 14 '13 at 21:07
  • I could provide an answer with a table that looks like yours but with less horizontal lines (the subpoints and -numbers would be collected in an additional table for each question). I'm reluctant to add a subquestions environment or similar to exsheets as I don't want to tie users to one solution or the other. IMHO the current way is more flexible. – clemens Jun 15 '13 at 11:50
  • @cgnieder I think such kind of subquestions would be useful, since most of the times in a question you start introducing the question with the background and some parameters and later you ask the real questions. Nevertheless, for me it would be useful to separate the code that enumerates the questions/subquestion and prints the scores of each. – cacamailg Jun 15 '13 at 12:02
2

You can adapt the code from the linked question to get something similar to the table you posted. I commented the code below so it hopefully becomes clear what everything does. It produces this grade table:

enter image description here

\documentclass[10pt,a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[pass,showframe]{geometry}
\usepackage{array,booktabs}
\usepackage{marginnote}
\usepackage{blindtext}

\usepackage[load-headings]{exsheets}
\SetupExSheets{
  solution/print = true,
  headings       = block-wp,
  counter-format = qu
}
% this requires version 0.9 of tasks.sty:
\settasks{
  counter-format = qu.tsk ,
  label-width    = 2em
}

\usepackage{etoolbox,expl3,xparse}
% declare` subpoints' and `subnumber' properties:
\DeclareQuestionProperty{subpoints}
\DeclareQuestionProperty{subnumber}
% switch to expl3 namespace and make @ a letter:
\makeatletter
\ExplSyntaxOn
% declare a temporary sequence variable for each property:
\seq_new:N \g_cacamailg_subpoints_seq
\seq_new:N \g_cacamailg_subnumber_seq

% the following assumes you're always going to use a {tasks}
% environment for the subquestions
\cs_new_protected:Npn \cacamailg_subpoints:n #1
  {
    % save the points in the one sequence...
    \seq_gput_right:Nx \g_cacamailg_subpoints_seq { #1 }
    % ... and the current current {tasks} label in the other:
    \seq_gput_right:Nx \g_cacamailg_subnumber_seq
      { \@cntfmts@parsed@pattern }
    % \addpoints adds the points to the current question points
    % and the total sum of points:
    \marginnote { \addpoints { #1 } }
    \ignorespaces
  }
\NewDocumentCommand \subpoints { m }
  { \cacamailg_subpoints:n { #1 } }

\cs_generate_variant:Nn \exsheets_set_question_properties:n { x }

% at the end of a {question}:
\AtEndEnvironment{question}
  {
    % are subpoints given?
    \seq_if_empty:NF \g_cacamailg_subpoints_seq
      {
        % then build a table of the subpoints and another one of the subpoints
        % to be used in the grade table later and save them both as question
        % property:
        \exsheets_set_question_properties:x
          {
            subpoints =
              {
                \exp_not:N \begin{tabular}[t]{@{}l@{}}
                  \seq_use:Nnnn \g_cacamailg_subpoints_seq {\\} {\\} {\\}
                \exp_not:N \end{tabular}
              } ,
            subnumber =
              {
                \exp_not:N \begin{tabular}[t]{@{}l@{}}
                  \seq_use:Nnnn \g_cacamailg_subnumber_seq {\\} {\\} {\\}
                \exp_not:N \end{tabular}
              }
          }
      }
    % clear both sequences:
    \seq_gclear:N \g_cacamailg_subpoints_seq
    \seq_gclear:N \g_cacamailg_subnumber_seq
  }
\ExplSyntaxOff
\makeatother

\begin{document}

\begin{question}
  \begin{tasks}
    \task \subpoints{1} \blindtext
    \task \subpoints{0.5} \blindtext
    \task \subpoints{1} \blindtext
    \task \subpoints{1} \blindtext
\end{tasks}
\end{question}

\begin{question}
  \begin{tasks}
    \task \subpoints{0.75} \blindtext
    \task \subpoints{0.75} \blindtext
    \task \subpoints{1.5} \blindtext
\end{tasks}
\end{question}

\null\vspace*{\fill}

\begin{center}
\begin{tabular}{|*4{l|}c|}\hline
  \multicolumn{2}{|c|}{Question } & \multicolumn{2}{c|}{ Points } & Notes \\ \hline
  \ForEachQuestion{
    \QuestionNumber{#1} &
    \GetQuestionProperty{subnumber}{#1} &
    \GetQuestionProperty{points}{#1} &
    \GetQuestionProperty{subpoints}{#1} &
    \iflastquestion{}{\tabularnewline\hline}
  }
  \\\hline
  \multicolumn{2}{|l|}{Total}  & \multicolumn{2}{r|}{\pointssum* } &\\\hline
\end{tabular}
\end{center}

\end{document}
  • Thank you very much! With that the table looks much better. I still think it would be a nice feature to add to exsheets package. – cacamailg Jun 15 '13 at 14:48
  • I deliberately chose not to add a grade table to exsheets but only the means for the users to create one themselves. There are many different layouts one can think of and I do not want to delimit design choices :) – clemens Jun 15 '13 at 14:55
  • 1
    I didn't mean to add the table as it is, but with subnumber and subpoints you add me more choices to design a suitable table. So options like subnumber and subpoints would be nice in the package. This answer can be a starting point :). – cacamailg Jun 15 '13 at 14:59
  • Every user can add as many properties to questions as they like: \DeclareQuestionProperty{property-I-need}. There's no need to use expl3, either. etoolbox' lists for example would work quite as well here... – clemens Jun 15 '13 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.