如何在同一练习类型中重置练习计数器。我不想创建不同的练习类型,因为我想创建问题库并使用收集选项。我已附加 MWE 和所需输出。我是初学者,即使有人可以使用 XSIM 改进我的代码,我也很开放。
我的MWE
\documentclass[a4paper,12pt]{article}
\usepackage{xsim}
\usepackage{tasks}
\settasks{
label = (\theexercise\arabic*) ,
label-width = 5ex,
item-indent=6ex
}
\DeclareExerciseType{question}{
exercise-env = question ,
solution-env = answer ,
exercise-name = Question ,
solution-name = Answer ,
exercise-template = item ,
solution-template = solution ,
% exercise/the-counter = \arabic{exercise}. ,
counter = exercise, % shares a counter with the `exercise' type
}
\DeclareExerciseEnvironmentTemplate{item}
{\item[\GetExerciseProperty{counter}]
\GetExercisePropertyT{points}
{%
\marginpar
{%
\par\vspace{2.5ex plus .2ex}
[\printgoal{\PropertyValue}]%
}%
}%
}%
{}
\DeclareExerciseEnvironmentTemplate{solution}
{\item[\GetExerciseProperty{counter}]}
{}
\newenvironment{questions}
{\itemize}
{\enditemize}
\newenvironment{answers}
{\itemize}
{\enditemize}
\usepackage{lipsum}
\xsimsetup{
exercise/the-counter = \arabic{exercise}.,
% exercise/within = section,
% answer/print = true,
}
\begin{document}
\section*{Section A}
\begin{questions}
\begin{question}[points=4]
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[66]
\end{answer}
\begin{question}
Answer the following questions.
\begin{tasks}
\task \lipsum[75]
\task question.
\end{tasks}
\end{question}
\begin{question}
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[75]
\end{answer}
\end{questions}
\section*{Section B}
\begin{questions}
\begin{question}[points=4]
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[66]
\end{answer}
\begin{question}
Answer the following questions.
\begin{tasks}
\task \lipsum[75]
\task question.
\end{tasks}
\end{question}
\begin{question}
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[75]
\end{answer}
\end{questions}
% \begin{answers}
% \item[] \printsolutions
% \end{answers}
\end{document}
所需输出:
答案1
用户卡博哈在评论中给出了解决方案的正确方向。
将设置添加到 后within=section
,\DeclareExerciseType
您所要做的就是重新定义命令\section
,使其不显示前面的数字部分。这可以通过标题安全包装,如图所示。
在此解决方案中,您使用的是\section
命令,而不是带星号的版本\section*
。
因此,使用此代码:
\documentclass[a4paper,12pt]{article}
\usepackage{xsim}
\usepackage{tasks}
\settasks{
label = (\theexercise\arabic*) ,
label-width = 5ex,
item-indent=6ex
}
\DeclareExerciseType{question}{
exercise-env = question ,
solution-env = answer ,
exercise-name = Question ,
solution-name = Answer ,
exercise-template = item ,
solution-template = solution ,
% exercise/the-counter = \arabic{exercise}. ,
counter = exercise, % shares a counter with the `exercise' type
within=section %% ADDED via comment by "cabohah"
}
\DeclareExerciseEnvironmentTemplate{item}
{\item[\GetExerciseProperty{counter}]
\GetExercisePropertyT{points}
{%
\marginpar
{%
\par\vspace{2.5ex plus .2ex}
[\printgoal{\PropertyValue}]%
}%
}%
}%
{}
\DeclareExerciseEnvironmentTemplate{solution}
{\item[\GetExerciseProperty{counter}]}
{}
\newenvironment{questions}
{\itemize}
{\enditemize}
\newenvironment{answers}
{\itemize}
{\enditemize}
\usepackage{lipsum}
\xsimsetup{
exercise/the-counter = \arabic{exercise}.,
%exercise/within = section,
% answer/print = true,
}
% Modifying the \section command
\usepackage{titlesec}
\titleformat{\section}[hang]%
{}%
{}%
{0pt}%
{\Large\textbf}%
\begin{document}
\section{Section A}
\begin{questions}
\begin{question}[points=4]
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[66]
\end{answer}
\begin{question}
Answer the following questions.
\begin{tasks}
\task \lipsum[75]
\task question.
\end{tasks}
\end{question}
\begin{question}
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[75]
\end{answer}
\end{questions}
\section{Section B}
\begin{questions}
\begin{question}[points=4]
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[66]
\end{answer}
\begin{question}
Answer the following questions.
\begin{tasks}
\task \lipsum[75]
\task question.
\end{tasks}
\end{question}
\begin{question}
\lipsum[66]
\end{question}
\begin{answer}
\lipsum[75]
\end{answer}
\end{questions}
\end{document}
您将获得: