Por que não há espaço após o cabeçalho da resposta?

Por que não há espaço após o cabeçalho da resposta?

Redefini o exercício e os cabeçalhos de resposta do exercisepacote da mesma maneira.

Após o cabeçalho do exercício, resta algum espaço, após o cabeçalho da resposta não.

Claro, posso colocar manualmente na definição do cabeçalho da resposta, mas estou me perguntando se é um bug do pacote ou algo que fiz de errado.

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

insira a descrição da imagem aqui

Responder1

A resposta está nas definições de \@@@ExeEnve\@@@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}

Como você pode ver, existe um fim de linha desprotegido na linha 371, que é o que produz o espaço após o “Exercício 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}

insira a descrição da imagem aqui

Responder2

Parece ser um bug para mim. Adicionando um espaço no final da definição

\renewcommand{\AnswerHeader}{\noindent\bfseries\AnswerName\ \thechapter.\ExerciseHeaderNB. }
%                                                                                        ^^^

resolve o problema como solução alternativa. Para mim, parece que falta uma \xspacedefinição para o texto do cabeçalho da solução no pacote ...

Na documentação você pode encontrar

\newcommand{\AnswerHeader}{\medskip\centerline{\textbf{Answer of \ExerciseName\ \ExerciseHeaderNB}\smallskip}}

surpreendente para mimcom um \smallskipno final.

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}

resultado:

pdf resultante

informação relacionada