1

I use the exam class to write my exercise sheets. Sometimes the solutions are printed and sometimes there are not.

When the solutions are not required I need the exercises to be printed one after one without a page break.

But when the solutions are printed I want each exercise to start on its own page.

My question is : how to modify the TheSolution environment in such a way that a page break is automatically inserted at its end?

MME:

\documentclass[a4paper,answers]{exam} 
   \usepackage{lipsum}
   \begin{document}
     \begin{questions}
       \question
         \lipsum[1]
         \begin{solution}
           \lipsum[2]
         \end{solution}
       \newpage % I need this to be  automatically inserted at the    end of each solution
      \question
         \lipsum[3]
         \begin{solution}
           \lipsum[4]
         \end{solution}
         \newpage 
       \question
          \lipsum[5]
          \begin{solution}
             \lipsum[6]
          \end{solution}
          \newpage 
    \end{questions}
\end{document}

1 Answer 1

2

I'm not sure if the exam class has a custom way to hook onto the end of each solution environment, but you can achieve the same with the AtEndEnvironment{environment}{code} command from the etoolbox package.

\documentclass[a4paper,answers]{exam} 
\usepackage{lipsum}

% ---------------------------------
\usepackage{etoolbox}
\AfterEndEnvironment{solution}{\newpage}

\begin{document}
 \begin{questions}
   \question
     \lipsum[1]
     \begin{solution}
       \lipsum[2]
     \end{solution}
%       \newpage % I need this to be  automatically inserted at the    end of each solution
  \question
     \lipsum[3]
     \begin{solution}
       \lipsum[4]
     \end{solution}
%         \newpage 
   \question
      \lipsum[5]
      \begin{solution}
         \lipsum[6]
      \end{solution}
%          \newpage 
\end{questions}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .