¿Por qué no queda espacio después del encabezado de respuesta?

¿Por qué no queda espacio después del encabezado de respuesta?

Redefiní el ejercicio y los encabezados de respuesta del exercisepaquete de la misma manera.

Después del encabezado del ejercicio queda correctamente un espacio, después del encabezado de respuesta no.

Por supuesto, puedo ponerlo manualmente en la definición del encabezado de respuesta, pero me pregunto si es un error del paquete o algo que hice mal.

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

ingrese la descripción de la imagen aquí

Respuesta1

La respuesta está en las definiciones de \@@@ExeEnvy\@@@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 puedes ver, hay un final de línea desprotegido en la línea 371, que es lo que produce el espacio después del “Ejercicio 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}

ingrese la descripción de la imagen aquí

Respuesta2

Parece ser un error para mí. Agregar un espacio al final de la definición

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

resuelve el problema como solución alternativa. Para mí, parece que falta \xspacela definición del texto del encabezado de la solución en el paquete...

En la documentación puedes encontrar

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

sorprendente para micon un \smallskipal 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

información relacionada