The following MWE demonstrates that the list of answers accumulated into a box does not respect page breaks when printed (code adapted from Multiple Choice Answer Key in exam package at the end of document:
\documentclass[answers]{exam}
\usepackage{pgffor}
\newbox\allanswers
\setbox\allanswers=\vbox{}
\newenvironment{answer}
{%
\global\setbox\allanswers=\vbox\bgroup %
\unvbox\allanswers%
\thequestion. \thechoice\\
}%
{%
\egroup%
}
\newcommand{\CC}{\CorrectChoice \leavevmode\begin{answer}\end{answer}}
\newcommand{\showallanswers}{%
\ifprintanswers \centering Here are the answers: \par \usebox\allanswers \fi}
\begin{document}
\begin{questions}
\foreach \i in {1,...,50}{
\question[5] Important Question 1
\begin{choices}
\CC 100
\end{choices}
}
\end{questions}
\newpage
\showallanswers
\end{document}
How can I format the content of the box so that it stays into the document margins (ideally it should be printed in a multicol environment, but I can't seem to do it)?
\usebox
prints an indivisible object.\unvbox\allanswers