為什麼答案標題後面沒有空格?

為什麼答案標題後面沒有空格?

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文件

相關內容