2

I want to append an answer sheet to an exam. However, I only managed to do so manually, which causes conflicts if I reference things (with \cref for instance). Also, if have to re-adjust the points in the answer sheet every time I change them in the questions. Is there a proper way of doing this?

\documentclass[addpoints, 12pt]{exam}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage[nameinlink]{cleveref}

\pagestyle{headandfoot}
\firstpageheader{\large\bfseries Astronomy Exam\\ \bigskip
\large\bfseries Last Name:\enspace\makebox[1.9in]{\hrulefill}}
{}
{\large\bfseries Univ ID: \makebox[2in]{\hrulefill} \\  \bigskip
 \large\bfseries First Name:\enspace\makebox[2in]{\hrulefill}}
\runningheader{\large\bfseries Last Name:\enspace\makebox[1.9in]{\hrulefill}}
{}
{\large\bfseries First Name:\enspace\makebox[2in]{\hrulefill}}
\firstpagefooter{}{}{}
\runningfooter{}{\thepage}{}

\begin{document}

\begin{center}
\fbox{\fbox{\parbox{5.5in}{\centering
Answer the questions in the spaces provided on the
answer sheets.}}}
\end{center}

\begin{questions}

\question[60] Explain Principle A

\question[40] Explain Principle B

\end{questions}

\newpage

\begin{center}
\fbox{\fbox{\parbox{5.5in}{\centering
Answer sheet}}}
\end{center}
\bigskip

\begin{questions}

\question[60] Answer:

\vspace{\stretch{1}}

\question[40] Answer:

\vspace{\stretch{1}}


\end{questions}

\end{document}
  • 1
    And the option to answer the questions below the question is not ok? For that you could use: \begin{solutionordottedlines}[5cm] \end{solutionordottedlines} There are a lot of variaties of this. – Arne Timperman Feb 13 '16 at 12:16
  • The problem is that some student have attempted to change their answers when they got it back. So I usually scan exams before returning to them. With answers all in the back, I don't have to scan everything. – capadocia Feb 13 '16 at 20:04
  • 1
    I see, no LaTeX solution for that from my part. A student solution: empty desk, and give it back at the end off the class? :-( – Arne Timperman Feb 13 '16 at 20:15
2

Hi I modified the answer from How to get LaTeX to expand at the correct position? to create a new environment for my answer booklet.

Here's the solution using your MWE

\documentclass[addpoints, 12pt]{exam}

\pagestyle{headandfoot}
\firstpageheader{\large\bfseries Astronomy Exam\\ \bigskip
\large\bfseries Last Name:\enspace\makebox[1.9in]{\hrulefill}}
{}
{\large\bfseries Univ ID: \makebox[2in]{\hrulefill} \\  \bigskip
 \large\bfseries First Name:\enspace\makebox[2in]{\hrulefill}}
\runningheader{\large\bfseries Last Name:\enspace\makebox[1.9in]{\hrulefill}}
{}
{\large\bfseries First Name:\enspace\makebox[2in]{\hrulefill}}
\firstpagefooter{}{}{}
\runningfooter{}{\thepage}{}

\usepackage{verbatim}

\newenvironment{ex@skripts}[1]{#1}{}

\makeatletter
\newwrite\verbatim@outSkr % Define file. 
\immediate\openout\verbatim@outSkr=\jobname.skr  % Open file for writing. 

\def\skript{
\@bsphack
\let\do\@makeother\dospecials
\catcode`\^^M\active
\def\verbatim@processline{%
\immediate\write\verbatim@outSkr{\the\verbatim@line}}%
\immediate\write\verbatim@outSkr{\string\begin{ex@skripts}{\expandafter\thequestion. (\expandafter\totalpoints \ points) Answer:\string\par}}
\verbatim@start}

\def\endskript{%
\immediate\write\verbatim@outSkr{\string\end{ex@skripts}}
\@esphack}

\newcommand*{\includeSkripts}{%
\immediate\closeout\verbatim@outSkr    % Close file. 
\InputIfFileExists{\jobname.skr}{}{}
\newwrite\verbatim@outSkr % Datei wird definiert 
\immediate\openout\verbatim@outSkr=\jobname.skr  % Open file for writing. 
}
\makeatother

\begin{document}

\begin{center}
\fbox{\fbox{\parbox{5.5in}{\centering
Answer the questions in the spaces provided on the
answer sheets.}}}
\end{center}

\begin{questions}

\question[60] Explain Principle A

\begin{skript}
\vspace{\stretch{1}}
\end{skript}

\question[40] Explain Principle B

\begin{skript}
\vspace{\stretch{1}}
\end{skript}

\end{questions}

\newpage

\begin{center}
\fbox{\fbox{\parbox{5.5in}{\centering
Answer sheet}}}
\end{center}
\bigskip

\includeSkripts

\end{document}

You can rename skript to something more obvious like answerbox. Basically it just writes the contents of the environment to a file and outputs it when \includeSkripts is called.

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.