我如何打印问题和部分的\labelwidth
/值?\labelsep
\documentclass{exam}
\usepackage{verbatim}
\renewcommand{\questionshook}{%
\setlength{\leftmargin}{0pt}%
\setlength{\labelwidth}{-\labelsep}%
}
\renewcommand{\partshook}{%
\setlength{\labelwidth}{8mm}%
\setlength{\leftmargin}{\labelwidth}%
\setlength{\labelsep}{0pt}%
\setlength{\itemsep}{0.5\baselineskip}%
\def\makelabel##1{##1}%
}
\begin{document}
The length of question \verb|\labelwidth| is ??? and its \verb|\labelsep| is ???, while the length of part \verb|\labelwidth| is ??? and its \verb|\labelsep| is ???.
\end{document}
答案1
您不能让一个长度寄存器保存两个不同的值。一旦执行\questionshook
,\labelwidth
将是-\labelsep
(无论后者可能具有什么值),并且执行 之后\partshook
,\labelwidth
将是8mm
。两者不能同时存在。
您可以做的是,将这些值保存在不同的寄存器中,例如\partlabelwidth
和\questionlabelwidth
,然后在文档中使用这些名称。
在下面的 MWE 中,我定义了四个新的长度寄存器,、、\partlabelsep
和。然后,在一个组内,我曾经使部分值处于活动状态,然后使用将它们复制到新寄存器\partlabelwidth
,然后将其复制到。请注意,有些值未在中初始化,因此这里的顺序很重要!\questionlabelsep
\questionlabelwidth
\partshook
\global\setcounter
\questionshook
\questionshook
当你拥有这些值时,你可以使用伟大的\the
打印它们的值:
\documentclass{exam}
\usepackage{verbatim}
\renewcommand{\questionshook}{%
\setlength{\leftmargin}{0pt}%
\setlength{\labelwidth}{-\labelsep}%
}
\renewcommand{\partshook}{%
\setlength{\labelwidth}{8mm}%
\setlength{\leftmargin}{\labelwidth}%
\setlength{\labelsep}{0pt}%
\setlength{\itemsep}{0.5\baselineskip}%
\def\makelabel##1{##1}%
}
\newlength{\partlabelsep}
\newlength{\partlabelwidth}
\newlength{\questionlabelsep}
\newlength{\questionlabelwidth}
\begingroup
\partshook
\global\setlength{\partlabelsep}{\labelsep}
\global\setlength{\partlabelwidth}{\labelwidth}
\questionshook
\global\setlength{\questionlabelsep}{\labelsep}
\global\setlength{\questionlabelwidth}{\labelwidth}
\endgroup
\begin{document}
The length of question \verb|\labelwidth| is \the\questionlabelwidth\ and its \verb|\labelsep| is \the\questionlabelsep,
while the length of part \verb|\labelwidth| is \the\partlabelwidth\ and its \verb|\labelsep| is \the\partlabelsep.
\end{document}