# Displaying Answers Using the Exam Class (too many lines in vbox - make two columns)

I use the exam class to write multiple choice tests in a couple of my classes. I use the following code to collect and then display the correct answers at the end of the test using the command \showallanswers.

%%%%%start code for printing answers
\CorrectChoiceEmphasis{} %% removes question answers being boldface on test
{%
\thequestion. \thechoice\\
}%
{%
\egroup%
}


This works perfectly as long as the test contains about 35 questions or less. If the test contains more questions, then the answer key gets cut off and all answers above 35 are not displayed. I suspect this is because a vbox is used to display the answers and a single page does not have enough lines. I'd greatly appreciate a little help with amending the above code to somehow accommodate a longer test. Is there way to have the answer key use two columns, if necessary? I tried to edit the code and apply the multicols package, but my macro making skills are not great.

Thank you very much in advance.

Here's a more complete MWE that will allow the entire document to compile:

\documentclass[addpoints,answers]{exam}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{multicol}
\footer{}{Page \thepage}{}
\title{Exam Title}
\header{Course}{Test 1 --- Form A}{Spring 2023}
%\footer{Page \thepage\ of \numpages}
%{}
%{Points earned: \makebox[.5in]{\hrulefill}\\
%out of a possible \pointsonpage{\thepage} points}

\CorrectChoiceEmphasis{} %% removes question answers being boldface on test
{%
\thequestion. \thechoice\\
}%
{%
\egroup%
}

\begin{document}
\begin{center}

\fbox{\fbox{\parbox{5.5in}{\centering
INSERT EXAM INSTRUCTIONS HERE.}}}
\end{center}
\vspace{0.1in}
\makebox[\textwidth]{Name:\enspace\hrulefill} \\

\begin{questions}
\begin{choices}
\choice Option 1
\choice Option 2
\CC Option 3
\choice Option 4
\end{choices}

\end{questions}
\newpage
\end{document}


• Please what is your minimal complete code that we can compile on our pc? Jan 25 at 19:32
• @twothirtyeight I see you have a counter for the questions \thequestion. So the obvious way to proceed would be to use that counter in a condition macro inside your \ifprintanswers. When \thequestion exceeds a certain value, a command like \clearpage or \switchcolumn should be issued after which the printing of the answers can continue. Unfortunately, that is as far as I can suggest. Writing macro's isn't my forte either, but maybe someone can put this idea into code. Jan 25 at 19:40
• @Sebastiano I edited the original post to include a complete MWE to allow folks to compile a demo document. Thank you for your help. Jan 26 at 0:35
• @twothirtyeight You are welcome. :-) Jan 26 at 9:09
• The code to gather and display answers was found on this post: tex.stackexchange.com/questions/238153/… Jan 26 at 17:56

I was able to to find a solution by viewing the post

Multiple Choice Answer Key in exam package at the end of document

The line

\ifprintanswers \centering Here are the answers: \par \usebox\allanswers \fi}

\ifprintanswers \centering Here are the answers: \par \unvbox\allanswers \fi}

and then the list of answers was allowed to break over multiple pages.