2

Following-up this answer, I would like to make the solution span the whole text width regardless of the question level while continuing over multiple pages.

\documentclass[answers]{exam}
\usepackage{lipsum}
\usepackage{mdframed}

\renewenvironment{TheSolution}{\begin{mdframed}[skipabove=\baselineskip,innertopmargin=\baselineskip,innerbottommargin=\baselineskip]
        \textbf{Solution:}\enspace\ignorespaces}{\end{mdframed}}

\begin{document}
    \begin{questions}
        \question A question.
        \begin{parts}
            \part part
            \begin{solution}
                The long solution continues onto another page: \lipsum[1-8]
            \end{solution}
        \end{parts}
    \end{questions}
\end{document}
Diaa
  • 9,599

2 Answers2

1

You can use \parshape inside a group. However, it is not looking well I think.

\documentclass[answers]{exam}
\usepackage{lipsum}
\usepackage{mdframed}

\renewenvironment{solution}
{\begingroup\par\parshape0%
\begin{mdframed}[skipabove=\baselineskip,
                 innertopmargin=\baselineskip,
                 innerbottommargin=\baselineskip,
                 userdefinedwidth=\textwidth]
\textbf{Solution:}\enspace\ignorespaces}
{\end{mdframed}\par\endgroup}

\begin{document}
    \begin{questions}
        \question A question.
        \begin{parts}
            \part part
            \begin{solution}
                The long solution continues onto another page: \lipsum[1-8]
            \end{solution}
        \end{parts}
    \end{questions}

    \lipsum[1]
\end{document}

enter image description here

enter image description here

  • Thanks for your answer. However, if you considered the solution of parts (as in my edited question), it won't work, and the result would be like this. – Diaa May 05 '19 at 01:15
  • @Diaa I edited my answer –  May 05 '19 at 01:26
1

For some reason, EnvFullwidth uses a \vbox which appears to be unnecessary and definitely prevents page breaking. As with any environment, the original values of @totalleftmargin etc are restored on exit.

\documentclass[answers]{exam}
\usepackage{lipsum}
\usepackage{showframe}

\makeatletter
\newenvironment{MyFullwidth}
  {\par\bigskip% \bigskip not really needed
    \leftskip=0pt \rightskip=0pt
    % We adjust \@totalleftmargin (and linewidth?) in case there's a
    % solution environment inside of the environment:
    \advance\linewidth\@totalleftmargin
    \@totalleftmargin=0pt
  }
  {\par}
\makeatother

\begin{document}
    \begin{questions}
        \question A question.
        \begin{parts}
            \part part
            \begin{MyFullwidth}
            \begin{solution}
                The long solution continues onto another page: \lipsum[1-8]
            \end{solution}
            \end{MyFullwidth}
        \end{parts}
    \end{questions}
\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120