运动后的空间

运动后的空间

以下示例是一个练习,后面跟着一个段落:

\documentclass{article}
\usepackage{xsim}
\begin{document}
\begin{exercise}
This is some text for an exercise.
\end{exercise}

And now a paragraph to test if there is a break.
\end{document}

这样会生成一个文档,其中练习的结尾和下一个段落之间没有空格。我意识到我可以\medskip在每次练习后手动添加空格,但这似乎不太符合习惯。确保每次练习后都跳过的最佳方法是什么?如果练习后有解决方案,这应该足够智能,不会跳过。

答案1

您可以使用post-hook,但我不建议\medskip,因为这样的空间会与另一个练习之前的空间堆积在一起。

但是,\addvspace{\medskipamount}不起作用,因为post-hook插入代码时 LaTeX 尚未结束一个段落。不幸的是,\par\addvspace{\medskipamount}也不起作用,因为其参数中\xsimsetup不接受。\par:-(

您可以基于默认模板定义一个新模板,或许还可以将其降级\subsection*\subsubsection*使其不那么突出。

\documentclass{article}
\usepackage{xsim}

\ExplSyntaxOn

\DeclareExerciseEnvironmentTemplate {wu}
  {
    \subsubsection*
      {
        \XSIMmixedcase { \GetExerciseName } \nobreakspace
        \GetExerciseProperty {counter}
        \IfInsideSolutionF
          {
            \IfExercisePropertySetT {subtitle}
              { ~ { \normalfont \itshape \GetExerciseProperty {subtitle} } }
          }
      }
    \GetExercisePropertyT {points}
      {
        \marginpar
          {
            \IfInsideSolutionF { \rule {1.2cm} {1pt} \slash }
            \printgoal {\PropertyValue}
            \GetExercisePropertyT {bonus-points}
              { \nobreakspace ( + \printgoal {\PropertyValue} ) }
            \nobreakspace\XSIMtranslate {point-abbr}
          }
      }
  }
  {\par\addvspace{\medskipamount}}

\ExplSyntaxOff

\xsimsetup{exercise/template=wu}


\begin{document}

\begin{exercise}
This is some text for an exercise.
\end{exercise}

And now a paragraph to test if there is a break.

\begin{exercise}
This is some text for an exercise.
\end{exercise}

\begin{exercise}
This is some text for an exercise.
\end{exercise}

\end{document}

在此处输入图片描述

如您所见,练习 2 和练习 3 之间的空间与练习 2 之前的空间相同。

答案2

正如@clemens在评论中所建议的,可以将代码添加到帖子挂钩中。修复方法如下:

\documentclass{article}
\usepackage{xsim}
\xsimsetup{exercise/post-hook={\medskip}}
\begin{document}
\begin{exercise}
This is some text for an exercise.
\end{exercise}
And now a paragraph to test if there is a break.
\end{document}

答案3

exercise/end-hook = {<code>} 

代码为结束练习“锻炼” 类型练习的钩子。

exercise/post-hook = {<code>} 

代码为运动后“锻炼” 类型练习的钩子。

方法A

\documentclass{article}
\usepackage{xsim}
\xsimsetup{exercise/end-hook={\medskip}}

\begin{document}
\begin{exercise}
This is some text for an exercise.
\end{exercise}
And now a paragraph to test if there is a break.
\end{document}

方法b

\documentclass{article}
\usepackage{xsim}

\usepackage{etoolbox} 
\AfterEndEnvironment{exercise}{\medskip}

\begin{document}
\begin{exercise}
This is some text for an exercise.
\end{exercise}
And now a paragraph to test if there is a break.
\end{document}

输出: 在此处输入图片描述

编辑:

\documentclass{article}
\usepackage{xsim}
\xsimsetup{exercise/end-hook={\vskip\baselineskip}}

\begin{document}
\begin{exercise}
This is some text for an exercise.
\end{exercise}
And now a paragraph to test if there is a break.
\end{document}

或者:

\usepackage{etoolbox} 
\AfterEndEnvironment{exercise}{\vskip\baselineskip}

输出编辑:

在此处输入图片描述

相关内容