我用cleveref
它来引用。有一组问题(可以是项目)及其子问题,当引用它们的标签时,我希望它们显示为“问题 1.1”或(最好)“子问题 2.3”。
tasks
但是我看不出有办法命名与关联的计数器\crefname
。我可以忍受,只要子问题的标点符号不妨碍。
这是我的 MWE 和一张解释这一切的图片。
\documentclass{article}
\usepackage{tasks,cleveref,xsim}
\crefname{exercise}{question}{questions}
% what should be the correct counter here, nothing seems to work
\crefname{tsk}{subquestion}{subquestions}
\crefname{subquestion}{subquestion}{subquestions}
\crefname{subquestionn}{subquestion}{subquestions}
\crefname{tsk[1]}{subquestion}{subquestions}
% type of subquestions
\NewTasks[counter-format = tsk[1]),label-format = \itshape]{parts}[\subquestion](2)
\NewTasks[counter-format = (tsk[1]*,label-format = \itshape]{follow}[\subquestionn](2)
% a hack just to get subquestion referencing
\newcommand{\refsubq}[1]{\cref{#1}.\ref{#1}}
\begin{document}
\begin{exercise}
what is the name of the game? \label{game}
\begin{parts}
\subquestion who plays the game? \label{game1}
\subquestion do they all lose? \label{game2}
\end{parts}
\end{exercise}
\begin{exercise}
what is the game? \label{name}
\begin{follow}
\subquestionn is it real? \label{name1}
\subquestionn have you played it? \label{name2}
\end{follow}
\end{exercise}
\section*{References}
\noindent Refer exercise basic = \ref{name}
\noindent Refer exercise cleverref = \cref{game}
\noindent Refer subquestion basic = \ref{game1}
\noindent Refer subquestion cleverref = \cref{game1} % ideally I want it to output "subquestion 1.1"
\noindent Refer subquestion refsubq = \refsubq{name2}
\end{document}
我的疑问是
- 如何
\cref
在引用子问题时打印“子问题”,在引用问题时打印“问题”?实际上,我想摆脱\refsubq
。 counter-format
如何在打印输出时去掉标点符号\cref
。MWE 和图片很好地解释了这一点?
这不是 -package 的问题。我发现withinxsim
也有同样的行为。\item
\item
答案1
您只需
- 最新
tasks
(自 2020/05/11 起), - 告诉
cleveref
使用计数器task
和 ref
定义新环境时相应地设置选项tasks
:
以下是您的 MWE 的改编版:
\documentclass{article}
\usepackage{tasks,cleveref,xsim}
\crefname{exercise}{question}{questions}
\crefname{task}{subquestion}{subquestions}
% type of subquestions
\newcommand*\Star{*}
\NewTasksEnvironment[
label = \arabic*),
ref = \theexercise.\arabic*) ,
label-format = \itshape ,
label-width = 15pt
]{parts}[\subquestion](2)
\NewTasksEnvironment[
label = (\arabic*\Star,
ref = \theexercise.(\arabic*\Star ,
label-format = \itshape,
label-width = 15pt
]{follow}[\subquestionn](2)
\begin{document}
\begin{exercise}
what is the name of the game? \label{game}
\begin{parts}
\subquestion who plays the game? \label{game1}
\subquestion do they all lose? \label{game2}
\end{parts}
\end{exercise}
\begin{exercise}
what is the game? \label{name}
\begin{follow}
\subquestionn is it real? \label{name1}
\subquestionn have you played it? \label{name2}
\end{follow}
\end{exercise}
\section*{References}
Refer exercise cleverref = \cref{game} \\
Refer subquestion cleverref = \cref{game1} \\
Refer subquestion cleverref = \cref{game2}
Refer exercise cleverref = \cref{name} \\
Refer subquestion cleverref = \cref{name1} \\
Refer subquestion cleverref = \cref{name2}
\end{document}