4

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

 \documentclass[UTF8,11pt,a4paper]{book}
\usepackage{kantlipsum}
\usepackage[load-tasks=true]{exsheets}

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

\usepackage{scrextend}% needed with a KOMA-Script class, `addmargin' environment
\usepackage{etoolbox}
\AtBeginEnvironment{question}{\addmargin[3em]{0em}}
\AtEndEnvironment{question}{\endaddmargin}
\AtBeginEnvironment{solution}{\addmargin[3em]{0em}}
\AtEndEnvironment{solution}{\endaddmargin}


\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:

enter image description here

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 !

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

1 Answers1

2

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{
  question/pre-hook = \addmargin[3em]{0em} ,
  question/post-hook = \endaddmargin ,
  solution/pre-hook = \addmargin[3em]{0em} ,
  solution/post-hook = \endaddmargin
}

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:

enter image description here

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

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

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

\SetupExSheets{
  question/pre-hook = \addmargin[3em]{0em} ,
  question/post-hook = \endaddmargin ,
  solution/pre-hook = \addmargin[3em]{0em} ,
  solution/post-hook = \endaddmargin
}

\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}
cgnieder
  • 66,645