3

We only have written (paper-pencil) exams, and we only have short/medium-sized string answers. In our current exams, we present the question, and leave some whitespace below (which varies depending on the expected length of the answer).

How can I flexibly add that whitespace below a question when I export a PDF from R/exams?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Felix S
  • 1,769
  • 2
  • 13
  • 17

2 Answers2

3

I asked this a while back on R-Forge and here is Achim Zeileis's answer:

  1. The easiest way to add enough white space below a question is to include some LaTeX command for this either in the exercise itself or (probably easier/better) in the LaTeX template. You could, for example, add a \vspace*{8cm} or a \newpage at the end of every exercise. For illustration I attach a plain-page.tex template that has:

    \newenvironment{question}{\item \textbf{Problem}\newline}{\newpage}
    

    where the \item ... \newline is added in the beginning of each exercise and \newpage at the end. Check out

    exams2pdf(c("tstat", "deriv"), template = "plain-page.tex")
    

    to see what it does. In case you want to have different amounts of white space for different questions, you should probably put a \vspace*{} into the exercises. There would be further fine-tuning options but maybe the solution above works well enough for you. Please keep asking otherwise.

https://r-forge.r-project.org/forum/message.php?msg_id=45361&group_id=1337 (You need to create an account to view.)

Here is the code from the attachment:

\documentclass[a4paper]{article}

\usepackage{a4wide,color,Sweave,url,amsmath,booktabs,longtable,verbatim}
\newenvironment{question}{\item \textbf{Problem}\newline}{\newpage}
\newenvironment{solution}{\comment}{\endcomment}
\newenvironment{answerlist}{\renewcommand{\labelenumi}
{(\alph{enumi})}\begin{enumerate}}{\end{enumerate}}

\begin{document}
\begin{enumerate}
%% \exinput{exercises}
\end{enumerate}
\end{document}
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
jtr13
  • 1,225
  • 11
  • 25
  • Thanks for pointing to this answer from our forum. Note that you can read the thread without registering: https://R-Forge.R-project.org/forum/forum.php?thread_id=33307&forum_id=4377&group_id=1337 Just accessing an individual message seems to require login because it apparently includes the possibility to answer. – Achim Zeileis May 14 '19 at 23:25
1

As pointed out by @jtr13 the easiest solution when all exercises get the same rule for the white space, e.g., a fixed amount or the rest of the page as shown in the post from the R-Forge forum.

If the white space amount varies from exercise to exercise (as mentioned in the original question) then a very simple solution is to include something like

\vspace*{5cm}

in every exercise and vary the amount of white space as needed. This works in both R/Markdown (.Rmd) and R/LaTeX (.Rnw) exercises with exams2pdf(). When converting to HTML (e.g., for Moodle etc.) it is simply ignored.

If it should be possible to optionally ignore the white space in the PDF as well (e.g., when compiling a question list as an overview rather than an exam), then I would use a custom dedicated command. This can then optionally be ignored by making the command inactive. Instead of \vspace you could use, say

\whitespace{5cm}

Then in the header of the LaTeX template you need to define the command, e.g.

\let\whitespace=\vspace

And in a template that should ignore the command you could say

\newcommand{\whitespace}[1]{}

For a concrete example of a LaTeX template see the answer by jtr13 or vignette("exams", package = "exams").

Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49
  • 1
    A note for users: It is important to add the * after the custom \whitespace command. Without *, the whitespace does not expand onto the next page. That means, if a question is printed at the bottom of a page, there would not be enough space for the answer. – Felix S Aug 02 '19 at 06:15