Skip to content

Instantly share code, notes, and snippets.

@jacintak
Last active December 31, 2022 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacintak/71c9978cc5b3d9a2c1b8f82403a31830 to your computer and use it in GitHub Desktop.
Save jacintak/71c9978cc5b3d9a2c1b8f82403a31830 to your computer and use it in GitHub Desktop.
[rmarkdown] LaTeX {exam} template with integrated R
\begin{coverpages}
\begin{center}
% provide instructions and details
\fbox{\fbox{\parbox{5.5in}{\centering
Answer the questions in the spaces provided on the question sheets. \linebreak
If you run out of room for an answer, continue on the back of the page.}}}
\end{center}
\vspace{1in}
\makebox[0.9\textwidth]{Name:\enspace\hrulefill}
\vspace{0.5in}
\makebox[0.9\textwidth]{Student Number:\enspace\hrulefill}
\vspace{1in}
% add grade table
\begin{center}
\gradetable[h]
\end{center}
\end{coverpages}
% header and footer
\thispagestyle{headandfoot}
\firstpageheader{}{Page \thepage\ of \numpages}{}
\runningheader{}{Page \thepage\ of \numpages}{}
\firstpagefooter{}{}{}
\runningfooter{}{}{}
\runningheadrule
\firstpageheadrule
% define questions and solutions and parts
\newcommand{\BQ}{\begin{questions}}
\newcommand{\EQ}{\end{questions}}
\newcommand{\BS}{\begin{solution}}
\newcommand{\ES}{\end{solution}}
\newcommand{\BP}{\begin{parts}}
\newcommand{\EP}{\end{parts}}
% pandoc does not understand parts. Must use {} in markdown
\renewcommand{\part}[1][]{\oldpart[1]{}}
---
title: "Class Code"
subtitle: "Exam Name"
date: "`r format(Sys.Date(), '%d-%m-%Y')`"
documentclass: exam
classoption: [answers, addpoints] # comment to hide answers
fontsize: 12pt
output:
pdf_document:
highlight: NULL
includes:
before_body: cover.tex
in_header: preamble.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.height = 4, fig.width = 4, fig.align = 'center')
```
\BQ
# Pressure
\question[5] Define pressure
\BS
* Under
* Pressure
\ES
\vspace{\stretch{5}}
\newpage
# Trees
\question Looks at the graph below
```{r trees}
plot(Height ~ Girth, trees)
```
\BP
\part[2]{} What is the predictor variable?
\BS
Girth
\ES
\vspace{\stretch{2}}
\part[3]{} What is the dependent variable?
\BS
Height
\ES
\vspace{\stretch{3}}
\EP
\EQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment