为什么答案标题后没有空格?

为什么答案标题后没有空格?

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末尾带有一个。

梅威瑟:

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

结果:

生成的 pdf

相关内容