3

Please see comments near lines 56 to 60 for requests.

%
%--------------------------------------------------------------------------------------------------------- %
\documentclass{book}
%--------------------------------------------------------------------------------------------------------- %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb} %
\usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,driver=none,lmargin=25mm,vmargin=20mm,showframe,showcrop]{geometry} % verbose,showcrop,showframe=inner frame
\usepackage[a4,frame,center]{crop} % pageframe
\usepackage[lastexercise,answerdelayed]{exercise}
%
\setlength{\marginparsep}{0mm} %
%
\renewcommand{\subQuestionNB}{\alph{subQuestion}) }

\renewcommand{\AnswerHeader}{\medskip{\textbf{\AnswerName\ %
    \ExerciseHeaderNB}\smallskip}}

\renewcommand{\ExerciseHeader}{\textbf{\quad\:\ExerciseName\;\ExerciseHeaderNB\ExerciseHeaderTitle\ExerciseHeaderOrigin} %
  \par\nopagebreak\medskip}

\setlength{\subQuestionIndent}{26pt}

\renewcounter{Exercise}[chapter] % Reset counter every chapter
\renewcounter{Answer}[chapter] %
\newcounter{Problem}[chapter] %
%
\def\AnswerName{\par{Answers to questions on section}} %
%
\begin{document}

\chapter{\fontsize{11}{12}\selectfont{This header would already be present within the book}}\vspace{-36pt}

\begin{Exercise}[label={chap_01_sec_01},name={Exercises on section},counter={Problem}]
  \Question{What is the symbol for iron?}
  \Question{What is the symbol for hydrogen?}
\end{Exercise}

\begin{Exercise}[label={chap_01_sec_02},name={Exercises on section},counter={Problem}]
  \Question{What is the symbol for lead?}
  \Question{For hydrogen, state the atomic number}
\end{Exercise}

\chapter{\fontsize{11}{12}\selectfont{This header would already be present within the book}}\vspace{-36pt}

\begin{Exercise}[label={chap_02_sec_01},name={Exercises on section},counter={Problem}]
  \Question{What is the symbol for copper?}
  \Question{What is the form of oxygen?}
\end{Exercise}

\begin{Exercise}[label={chap_02_sec_02},name={Exercises on section},counter={Problem}]
  \Question{What is the symbol for zinc?}
  \Question{What is the form of zinc}
\end{Exercise}
%
% There are four sets of answers that follow
% The first two sets belong to chapter 1, the second two sets to chapter 2
%
% I want a chapter 1 header to go here
%
  \begin{Answer}[ref={chap_01_sec_01}]
    \Question{Fe=iron}     
  \Question{H} 
  \end{Answer}

  \begin{Answer}[ref={chap_01_sec_02}]
  \Question{Pb=lead}
    \Question{1}
  \end{Answer}

% and a chapter 2 header to go here

  \begin{Answer}[ref={chap_02_sec_01}]
    \Question{Cu=copper}     
  \Question{oxygen is a gas} 
  \end{Answer}

  \begin{Answer}[ref={chap_02_sec_02}]
  \Question{Zn=zinc}
    \Question{zinc is a metal}
  \end{Answer}

\shipoutAnswer

\end{document}
8
  • 5
    Maybe you can reduce your code to a minimum and try to clarify your problem. At the moment, at least I, do not understand what you want. Commented May 3, 2017 at 18:16
  • The answers resulting from \shipoutAnswer appear as one block without any headers to indicate which of the two chapters they belong. I want a header, say, Answers to Chapter 1, then later Answers to Chapter 2.
    – keith77777
    Commented May 4, 2017 at 0:44
  • I think there must be a suitable command that is understood within the exercise environment, but I cannot find it.
    – keith77777
    Commented May 4, 2017 at 10:55
  • Again, I think you should delete all code that is not relevant to the problem. At the moment there is much irrelevant code. And it's easier if you change your question and don't clarify it within a comment. Commented May 4, 2017 at 18:30
  • OK. I can remove the unwanted code, but I'm not sure how to change the question within Stack Exchange. Would it be acceptable to start again and open a revised question?
    – keith77777
    Commented May 5, 2017 at 2:56

1 Answer 1

3
+50

I've created two commands:

  1. \answerheaderchap{\ref{chap:...}} to put before the first answer of a chapter with the \ref{chap:...} to that chapter (of course, put the corresponding \label{chap:...} after the \chapter command)
  2. \restoreanswerheader to put after the first answer of the chapter.

I've also inserted an unnumbered chapter title (if you like) before the list of the answer.

%
%--------------------------------------------------------------------------------------------------------- %
\documentclass{book}
%--------------------------------------------------------------------------------------------------------- %
%
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm,amssymb} %
\usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,driver=none,lmargin=25mm,vmargin=20mm,showframe,showcrop]{geometry} % verbose,showcrop,showframe=inner frame
\usepackage[a4,frame,center]{crop} % pageframe
\usepackage[lastexercise,answerdelayed]{exercise}
%
\setlength{\marginparsep}{0mm} %
%
\renewcommand{\subQuestionNB}{\alph{subQuestion}) }

\renewcommand{\AnswerHeader}{\medskip{\textbf{\AnswerName\ %
            \ExerciseHeaderNB}\smallskip}}

\renewcommand{\ExerciseHeader}{\textbf{\quad\:\ExerciseName\;\ExerciseHeaderNB\ExerciseHeaderTitle\ExerciseHeaderOrigin} %
    \par\nopagebreak\medskip}

\setlength{\subQuestionIndent}{26pt}

\renewcounter{Exercise}[chapter] % Reset counter every chapter
\renewcounter{Answer}[chapter] %
\newcounter{Problem}[chapter] %
%
\def\AnswerName{\par{Answers to questions on section}} %
%
\newcommand{\answerheaderchap}[1]{\renewcommand{\AnswerHeader}{\textbf{Chapter #1}\smallskip
        \textbf{\AnswerName\ \ExerciseHeaderNB}\smallskip}}
\newcommand{\restoreanswerheader}{\renewcommand{\AnswerHeader}{\textbf{\AnswerName\ \ExerciseHeaderNB}\smallskip}}
\begin{document}

    \chapter{\fontsize{11}{12}\selectfont{This header would already be present within the book}}\label{chap:1}\vspace{-36pt}

    \begin{Exercise}[label={chap_01_sec_01},name={Exercises on section},counter={Problem}]
        \Question{What is the symbol for iron?}
        \Question{What is the symbol for hydrogen?}
    \end{Exercise}

    \begin{Exercise}[label={chap_01_sec_02},name={Exercises on section},counter={Problem}]
        \Question{What is the symbol for lead?}
        \Question{For hydrogen, state the atomic number}
    \end{Exercise}

    \chapter{\fontsize{11}{12}\selectfont{This header would already be present within the book}}\label{chap:2}\vspace{-36pt}

    \begin{Exercise}[label={chap_02_sec_01},name={Exercises on section},counter={Problem}]
        \Question{What is the symbol for copper?}
        \Question{What is the form of oxygen?}
    \end{Exercise}

    \begin{Exercise}[label={chap_02_sec_02},name={Exercises on section},counter={Problem}]
        \Question{What is the symbol for zinc?}
        \Question{What is the form of zinc}
    \end{Exercise}
    %
    % There are four sets of answers that follow
    % The first two sets belong to chapter 1, the second two sets to chapter 2
    %
    % I want a chapter 1 header to go here
    %
    \answerheaderchap{\ref{chap:1}}
    \begin{Answer}[ref={chap_01_sec_01}]
        \Question{Fe=iron}     
        \Question{H} 
    \end{Answer}
    \restoreanswerheader

    \begin{Answer}[ref={chap_01_sec_02}]
        \Question{Pb=lead}
        \Question{1}
    \end{Answer}

    % and a chapter 2 header to go here
    \answerheaderchap{\ref{chap:2}}
    \begin{Answer}[ref={chap_02_sec_01}]
        \Question{Cu=copper}     
        \Question{oxygen is a gas} 
    \end{Answer}
    \restoreanswerheader

    \begin{Answer}[ref={chap_02_sec_02}]
        \Question{Zn=zinc}
        \Question{zinc is a metal}
    \end{Answer}

    \chapter*{\fontsize{11}{12}\selectfont{Solutions to the exercises}}
    \shipoutAnswer

\end{document}

I hope this is the output you're looking for:

enter image description here

1
  • Yes, that is exactly what I was looking for - thanks.
    – keith77777
    Commented May 10, 2017 at 10:43

You must log in to answer this question.

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