Search code examples
rr-exams

How to add a line in the pdf generated pdf by `exams` using the `exams2nops`?


We are generating a pdf through exams2nops using the items in blocks of choice, we would like to delimitate the blocks in the PDF adding a horizontal line after the last exercise of each block. Having that in mind we added a ***, ---, <hr/> however the behavior was always the same:

enter image description here

I would like a single line without adding the exercise number that's next in the exam:

enter image description here


Solution

  • It is not so easy to solve this by putting the horizontal line into the exercise file. The reason is that the line is needed after the answerlist but the answerlist is not formatted in the exercise but by exams2nops.

    A workaround is to tweak the definition of the {question} environment in the LaTeX template used by exams2nops. By default this is simply:

    \newenvironment{question}{\item}{}
    

    Where \item is executed at the beginning of the {question} and nothing at the end of it. Changing this by

    \renewenvironment{question}{\item}{\hrulefill}
    

    would insert a horizontal line after every question. If you just want it after selected questions you need to insert if/else statements for certain enumerated items. For example, for inserting the horizontal rule after the second item only, you can redefine:

    \renewenvironment{question}{\item}{\ifnum\value{enumi}=2 {\hrulefill} \else {} \fi}
    

    Thus, you get the enumi counter from the {enumerate} environment that you use and compare it with 2. If true, you insert the horizontal line, and otherwise you do nothing.

    Adding escapes for the backslashes you can pass this re-definition to exams2nops through the header argument:

    exams2nops(c("swisscapital", "switzerland", "tstat2", "deriv2"),
      header = "\\renewenvironment{question}{\\item}{\\ifnum\\value{enumi}=2 {\\hrulefill} \\else {} \\fi}")
    

    The resulting output is:

    exams2nops output with hrulefill tweak