
exercise
同じ方法で、パッケージの演習と回答のヘッダーを再定義しました。
演習のヘッダーの後には、回答のヘッダー番号の後に、いくらかのスペースが残っています。
もちろん、回答ヘッダーの定義に手動で追加することもできますが、パッケージのバグなのか、それとも私が間違ったことをしたのか疑問に思っています。
\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}
答え1
\@@@ExeEnv
答えはとの定義にあります\@@@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}
ご覧のとおり、行 371 には保護されていない行末があり、これが「演習 1.1」の後のスペースを生成しています。
\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}
答え2
私にとってはバグのようです。定義の最後にスペースを追加する
\renewcommand{\AnswerHeader}{\noindent\bfseries\AnswerName\ \thechapter.\ExerciseHeaderNB. }
% ^^^
回避策として問題を解決します。私の場合、\xspace
パッケージ内のソリューション ヘッダー テキストの定義が欠落しているようです...
ドキュメントには
\newcommand{\AnswerHeader}{\medskip\centerline{\textbf{Answer of \ExerciseName\ \ExerciseHeaderNB}\smallskip}}
私にとっては驚くべきことだ\smallskip
最後にが付きます。
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}
結果: