Xsim 包:无论是否打印解决方案,空间都是相同的

Xsim 包:无论是否打印解决方案,空间都是相同的

无论是否打印解决方案,我都希望留下相同的空间。

  • 如果练习中没有子问题,那么这个 MWE 就很好
  • 如果练习中有子问题,则此 MWE 不好

我尝试枚举子问题并将解决方案环境嵌套在练习环境中,但效果不佳,因为:

  • 不能为不同的子问题设置不同的解空间。
  • 您不能参考问题的计数器
  • 当 solution/print=false 时,它​​不会留下空白空间(见图)

有人知道更好的(不同的)方法吗?

\documentclass[]{article}
\usepackage{lipsum,tcolorbox,needspace,xsim}
\usepackage{enumitem}
% XSIM Settings
\xsimsetup{
    path=cache,
    file-extension=aux,
    blank/blank-style={#1},
    blank/filled-style=\textcolor{blue}{#1},
    blank/line-minimum-length=2cm,
    solution/print=true
}

\SetExerciseParameters{exercise}{
    exercise-name = \XSIMtranslate{exercise},
    exercise-template = exercise,
    solution-template = exercise,
    counter = section,
    counter-within = chapter
}

\DeclareExerciseType{question}{
    exercise-env = question,
    solution-env = answer,
    exercise-name = \XSIMtranslate{question},
    solution-name = \XSIMtranslate{solution},
    exercise-template = exercise,
    solution-template = exercise
}

\newlength{\defaultsolutionspace}
\setlength{\defaultsolutionspace}{2cm}
\newlength{\solutionspace}
\setlength{\solutionspace}{\defaultsolutionspace}
\DeclareExerciseProperty{solutionspace}

\DeclareExerciseEnvironmentTemplate{exercise}{%
    \IfExercisePropertySetTF{solutionspace}{
        \setlength{\solutionspace}{\GetExerciseProperty{solutionspace}}
    }{\setlength{\solutionspace}{\defaultsolutionspace}}
    \IfInsideSolutionTF{
        \tcolorbox[
        detach title,
        title        = \XSIMtranslate{solution},
        before upper = {\tcbtitle\par} ,
        fonttitle    = \bfseries,
        fontupper    = \normalsize,
        valign       = top,
        colframe     = black!20!white,
        colback      = black!3!white,
        coltext      = black,
        coltitle     = black,
        height       = \solutionspace,
        boxrule      = 0.5pt,
        width        = \linewidth,
        left         = 2mm,
        sharp corners
        ]
    }{
        \needspace{\solutionspace}
        \subsection*{%
            \XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}
            \GetExercisePropertyT{subtitle}{~\normalfont\itshape\PropertyValue}%
            \GetExercisePropertyT{points}{~\normalfont(\PropertyValue~P)}
            \GetExercisePropertyT{ID}{\label{ex:\PropertyValue}}
        }
    }
}{  
    \IfInsideSolutionTF{\endtcolorbox}{
        % fill out template
        \IfSolutionPrintF{
            \IfExistSolutionT{
                \tcolorbox[
                detach title,
                fonttitle    = \bfseries,
                fontupper    = \normalsize,
                valign       = top,
                colframe     = white,
                colback      = white,
                coltext      = blue,
                coltitle     = black,
                height       = \solutionspace,
                boxrule      = 0.5pt,
                width        = \linewidth,
                left         = 2mm,
                sharp corners
                ]
                \endtcolorbox
            }
        }
    }
}

\begin{document}
    \begin{exercise}[points=2,solutionspace=4cm]
        \lipsum[2]
    \end{exercise}
    \begin{solution}
        \lipsum[2]
    \end{solution}
\begin{exercise}[points=2,solutionspace=5cm]
    \begin{enumerate}[label=(\alph*)]
        \item subquestion 1
        \begin{solution}
        \lipsum[2]
        \end{solution}
        \item subquestion 2
                \begin{solution}
            \lipsum[2]
        \end{solution}
    \end{enumerate}
\end{exercise}

\end{document}

在此处输入图片描述

相关内容