
Ich habe die Übungs- und Antwortüberschriften des exercise
Pakets auf die gleiche Weise neu definiert.
Nach der Übungsüberschrift ist korrekterweise noch etwas Platz frei, nach der Antwortüberschrift Nr.
Natürlich kann ich es manuell in die Definition des Antwortheaders einfügen, aber ich frage mich, ob es ein Fehler des Pakets ist oder ob ich etwas falsch gemacht habe.
\documentclass{book}
\usepackage{amsmath}
\usepackage[lastexercise]{exercise}
\setlength{\ExerciseSkipBefore}{\baselineskip}
\setlength{\ExerciseSkipAfter}{1\baselineskip}
\setlength{\AnswerSkipBefore}{0\baselineskip}
\setlength{\AnswerSkipAfter}{1.2\baselineskip}
\renewcounter{Exercise}[chapter]
\renewcommand{\ExerciseHeader}{\noindent\bfseries\ExerciseName\ \thechapter.\ExerciseHeaderNB.}
\renewcommand{\AnswerName}{Solution}
\renewcommand{\AnswerHeader}{\noindent\bfseries\AnswerName\ \thechapter.\ExerciseHeaderNB.}
\begin{document}
\chapter{My first chapter}
\section{Problems}
\begin{Exercise}
Text of the 1st problem
\end{Exercise}
\begin{Answer}
Text of the solution of the 1st problem
\end{Answer}
\begin{Exercise}
Text of the 2nd problem
\end{Exercise}
\begin{Answer}
Text of the solution of the 2nd problem
\end{Answer}
\begin{Exercise}
Text of the 3rd problem
\end{Exercise}
\begin{Answer}
Text of the solution of the 3rd problem
\end{Answer}
\end{document}
Antwort1
Die Antwort liegt in den Definitionen von \@@@ExeEnv
und\@@@AnswerEnv
% exercise.sty, line 365:
\newcommand{\@@@ExeEnv}{%
\pagebreak[1]\vskip\ExerciseSkipBefore
\@QuestionLevel1
\refstepExecounter
\begingroup\@getExerciseInfo\ExerciseHeader
\addcontentsline{\ext@exercise}{\toc@exercise}{\ExerciseName\
\theExercise\ \expandafter{\itshape \ExerciseTitle}\hspace{.66em}}
\endgroup\AtBeginExercise}
% exercise.sty, line 656:
\newcommand{\@@@AnswerEnv}{%
\pagebreak[1]\vskip\AnswerSkipBefore\@QuestionLevel1
\begingroup\@getAnswerInfo\AnswerHeader\endgroup\AtBeginAnswer}
Wie Sie sehen, gibt es in Zeile 371 ein ungeschütztes Zeilenende, das das Leerzeichen nach „Übung 1.1“ erzeugt.
\documentclass{book}
\usepackage{amsmath}
\usepackage[lastexercise]{exercise}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@@@ExeEnv}{ \endgroup}{\endgroup}{}{} % remove the wrong space
\makeatother
\setlength{\ExerciseSkipBefore}{\baselineskip}
\setlength{\ExerciseSkipAfter}{1\baselineskip}
\setlength{\AnswerSkipBefore}{0\baselineskip}
\setlength{\AnswerSkipAfter}{1.2\baselineskip}
\renewcounter{Exercise}[chapter]
\renewcommand{\ExerciseHeader}{%
\noindent\bfseries\ExerciseName\ \thechapter.\ExerciseHeaderNB. %
}
\renewcommand{\AnswerName}{Solution}
\renewcommand{\AnswerHeader}{%
\noindent\bfseries\AnswerName\ \thechapter.\ExerciseHeaderNB. %
}
\begin{document}
\chapter{My first chapter}
\section{Problems}
\begin{Exercise}
Text of the 1st problem
\end{Exercise}
\begin{Answer}
Text of the solution of the 1st problem
\end{Answer}
\begin{Exercise}
Text of the 2nd problem
\end{Exercise}
\begin{Answer}
Text of the solution of the 2nd problem
\end{Answer}
\begin{Exercise}
Text of the 3rd problem
\end{Exercise}
\begin{Answer}
Text of the solution of the 3rd problem
\end{Answer}
\end{document}
Antwort2
Scheint für mich ein Fehler zu sein. Das Hinzufügen eines Leerzeichens am Ende der Definition
\renewcommand{\AnswerHeader}{\noindent\bfseries\AnswerName\ \thechapter.\ExerciseHeaderNB. }
% ^^^
löst das Problem als Workaround. Mir scheint, dass \xspace
in der Definition des Lösungsheadertexts im Paket etwas fehlt ...
In der Dokumentation finden Sie
\newcommand{\AnswerHeader}{\medskip\centerline{\textbf{Answer of \ExerciseName\ \ExerciseHeaderNB}\smallskip}}
für mich erstaunlichmit einem \smallskip
am Ende.
MWE:
\documentclass{book}
\usepackage{amsmath}
\usepackage[lastexercise]{exercise}
\setlength{\ExerciseSkipBefore}{\baselineskip}
\setlength{\ExerciseSkipAfter}{1\baselineskip}
\setlength{\AnswerSkipBefore}{0\baselineskip}
\setlength{\AnswerSkipAfter}{1.2\baselineskip}
\renewcounter{Exercise}[chapter]
\renewcommand{\ExerciseHeader}{\noindent\bfseries\ExerciseName\ \thechapter.\ExerciseHeaderNB.}
\renewcommand{\AnswerName}{Solution}
\renewcommand{\AnswerHeader}{\noindent\bfseries\AnswerName\ \thechapter.\ExerciseHeaderNB. }
\begin{document}
\chapter{My first chapter}
\section{Problems}
\begin{Exercise}
Text of the 1st problem
\end{Exercise}
\begin{Answer}
Text of the solution of the 1st problem
\end{Answer}
\begin{Exercise}
Text of the 2nd problem
\end{Exercise}
\begin{Answer}
Text of the solution of the 2nd problem
\end{Answer}
\begin{Exercise}
Text of the 3rd problem
\end{Exercise}
\begin{Answer}
Text of the solution of the 3rd problem
\end{Answer}
\end{document}
Ergebnis: