# Aligning Exsheets Answer with \printsolutions

When using exsheets package,I have a problem with \printsolution[all].

 \documentclass[UTF8,11pt,a4paper]{book}
\usepackage{kantlipsum}

runin = true ,
number-post-code = \space ,
attach = { main[r,vc]number[l,vc](-3em,0pt) } ,
above = 0pt,
below = 0pt
}
\SetupExSheets{
%  solution/print = true ,
%  counter-format = ch.qu ,
counter-within = chapter
}

\usepackage{scrextend}% needed with a KOMA-Script class, addmargin' environment
\usepackage{etoolbox}

\begin{document}

\chapter{One}

\section{Sec.\thesection }
This is  normal  text.

\section*{Using solution environment in section  }

\begin{question}
This is sample question 1.
\end{question}

\begin{solution}
This is sample solution 1.
\end{solution}

\begin{question}
This is sample question 2.
\end{question}

\begin{solution}
This is sample solution 2.
\end{solution}

This is normal text. This is normal text. This is normal text. This is normal text. This is normal text.

\section*{Using printsolutions at the end}

\printsolutions

This is normal text. This is normal text. This is normal text. This is normal text. This is normal text.

\end{document}


Output:

The exsheet package works well in the section, but when using \printsolutions at the end of book, the answer beyond the margin. I don't kown how to correct it, anyone can help me ? Thanks !

• I want to indent the answer after \printsolutions, same as with solution environment. – bech Nov 17 '14 at 6:10

Since the solution envorinment is not used by \printsolutions \AtBeginEnvironment{solution}{...} has no effect on the solutions printed there.

The solution: use the pre-hook and post-hook options for questions and solutions:

\SetupExSheets{
}


The cossesponding code will be used before and after each solution that gest printed, if through the solution environment of through \printsolution.

A complete example:

\documentclass[11pt,a4paper]{book}
\usepackage{kantlipsum}
\usepackage{exsheets}

runin = true ,
number-post-code = \space ,
attach = { main[r,vc]number[l,vc](-3em,0pt) } ,
above = 0pt,
below = 0pt
}
\SetupExSheets{
%  solution/print = true ,
counter-within = chapter
}

\usepackage{scrextend}% needed with a KOMA-Script class, addmargin' environment

\SetupExSheets{
}

\begin{document}

\section{Sec.\thesection}
This is  normal  text.

\section*{Using solution environment in section}

\begin{question}
This is sample question 1.
\end{question}

\begin{solution}
This is sample solution 1.
\end{solution}

\begin{question}
This is sample question 2.
\end{question}

\begin{solution}
This is sample solution 2.
\end{solution}

This is normal text. This is normal text. This is normal text. This is normal
text. This is normal text.

\section*{Using printsolutions at the end}

\printsolutions

This is normal text. This is normal text. This is normal text. This is normal
text. This is normal text.

\end{document}