Reputation: 25483
I would like to configure the answer list in R/exams to be distributed by columns:
A. Answer 1. C. Answer 3.
B. Answer 2. D. Answer 4.
In LaTeX, I have used the multicol
package. Is that possible with R/exams as well?
Upvotes: 1
Views: 380
Reputation: 17213
The R/exams interfaces intended for producing PDF files for printing on paper are exams2pdf()
and exams2nops()
(which is built on top of exams2pdf()
). Both of these use LaTeX in the background and allow to tweak the environment that is used for rendering the answer list. So the answer is: Yes, you can also use {multicols}
environment from the multicol
LaTeX package for this.
More specifically, in the LaTeX code your answer list will be written as:
\begin{answerlist}
\item Answer 1.
\item Answer 2.
\item Answer 3.
\item Answer 4.
\end{answerlist}
The rendering of this {answerlist}
then depends on the definition of this environment in the header of the document. The default in exams2nops()
as well as the demo templates for exams2pdf()
shipped along with the package is:
\newenvironment{answerlist}%
{\renewcommand{\labelenumii}{(\alph{enumii})}\begin{enumerate}}%
{\end{enumerate}}
In short, this simply uses the standard {enumerate}
environment and switches the counter to (\alph{...})
formatting, i.e., (a), (b), .... In exams2nops()
this yields the following output by default:
Alternatively, you can (re-)define this environment in the following way which uses a {multicols}{2}
layout and switches the formatting of the counter to A., B., ...
\newenvironment{answerlist}%
{\renewcommand{\labelenumii}{\Alph{enumii}.}\begin{multicols}{2}\begin{enumerate}}%
{\end{enumerate}\end{multicols}}
When you are using exams2pdf()
you can simply define the {answerlist}
environment like this in the LaTeX master template that you pass to exams2pdf(..., template = ...)
.
And when you are using exams2nops()
you can re-define the {answerlist}
environment on-the-fly in the header
:
multicol <- "\\renewenvironment{answerlist}{\\renewcommand{\\labelenumii}{\\Alph{enumii}.}\\begin{multicols}{2}\\begin{enumerate}}{\\end{enumerate}\\end{multicols}}"
exams2nops(..., header = multicol)
This yields:
Depending on the typical length of the items in your answer list you might, of course, also use more columns, e.g., {multicols}{4}
.
Furthermore, there is also the built-in option exams2nops(..., twocolumn = TRUE)
that switches the layout of the entire document to two columns (as opposed to only the answer list). A demo screenshot is included below.
Finally, some more variations that use the LaTeX environments {paralist}
or {enumitem}
instead of {multicols}
are discussed in this thread in the R/exams forum on R-Forge: https://R-Forge.R-project.org/forum/forum.php?thread_id=33823&forum_id=4377&group_id=1337.
Upvotes: 1