# Solutions in exam class

I'm trying to write up solutions to some exercises, using the exam class. In order to align equations correctly, I'm also using the aligned environment from amsmath.

%\AtEndEnvironment{solution}{\end{aligned}$} \section{Basic Algebra} \exercise{} \begin{questions} \question Simplify the following expressions by collecting like terms: \begin{parts} \part$8x + 3x + 4x - 6x$\begin{solution}$\begin{aligned}
3p + 3 + 5p - 7 - 7p - 9 &= 3p + 5p - 7p + 3 - 7 - 9\\
\BODY
\end{alignedat}$\end{solution} } \include{Chapter1} \end{document}  # Code - Chapter1.tex \section{Basic Algebra} \exercise{} \begin{questions} \question Solve the following equations. \begin{parts} \part$5a - 32 = 68\begin{sol} 5a - 32 = 68 &\implies 5a &= 100\\ &\implies \ans{a &= 20} \end{sol} \end{parts} \end{questions}  - try environ package to extract the contents of the solution env, and then wrap it in aligned when you insert it again. But why are you combining  and aligned, why not just use align*? Will there never be any solution with text? –  daleif May 17 '13 at 11:54
Using align* centres the solution; an effect that I do not want in this situation. Using environ seems to do the trick, thanks. –  JustinT May 17 '13 at 12:59
did you try newenvironment{sol}{/begin{solution}/begin{alignedat}{2}}{/end{alignedat}/end{s‌​olution}}? –  long tom May 21 '13 at 8:45

Turns out the problem was with the alignment points in Chapter1.tex

I hadn't fully understood that the & (effectively) get used alternately, 'odd numbered' occurrences as alignment points (with the column to the left aligned to the right, and the column to the right aligned to the left), and 'even numbered' occurrences used to separate the groups of columns.

Hence if you were to use 5a - 32 = 68 &\implies 5a &= 100 (as above), this would get typeset with 5a - 32 = 68 aligned to the right, \implies set between the columns, then 5a aligned to the left, = between columns, and 68 aligned to the right. The correct usage is

\section{Basic Algebra}

\exercise{}
\begin{questions}
\question Solve the following equations.
\begin{parts}
\part $5a - 32 = 68$
\begin{sol}
5a - 32 = 68 &\implies & 5a &= 100\\
&\implies & \ans{a &= 20}
\end{sol}
\end{parts}
\end{questions}


Note the extra & following the &\implies, to start a new alignment group.

-