Exsheets:如何获取结合部分和问题编号的计数器/参考

Exsheets:如何获取结合部分和问题编号的计数器/参考

我正在编写一个包含几个主要部分的文档,每个部分都会有一些练习和解决方案。我正在使用 exsheets 包,它似乎可以完成我想要的几乎所有工作。但是,我对如何使我的编号和引用按我想要的方式工作感到困惑。我希望问题编号为 SQ,其中 S 是部分编号,Q 是问题编号。我使用了 counter-format 和 counter-within-section 选项来执行此操作,它看起来就像我在文档中想要的那样。唯一的问题是,我希望能够通过这些数字来引用练习,但如果我在问题中使用标签,计数器似乎只会跟踪 Q。例如,我可以通过使用多个引用来获得我想要的效果\ref{s:seclabel}.\ref{q:exlabel}。但这似乎很笨拙,我每次都必须查找部分标签。我原本以为当我设置选项时,counter-within它也会使参考编号按我想要的方式工作,但似乎并非如此。有没有比我的黑客方法更好的方法?

我附上了一个使用我提出的解决方案的 MWE,这样你就可以看到我希望它做什么。关键部分是第 2 节中的参考资料。在 MWE 中,我还引用了一个问题的子部分,它需要单独的引用。说实话,我不确定我是否需要这样做,而且我怀疑这会更加棘手,因为我有一个单独的枚举环境。但如果有人能想出一个处理这个问题的通用解决方案,那就更好了。)

\documentclass[11pt]{article}

\usepackage[counter-format=se.qu,counter-within=section]{exsheets}
\usepackage{enumitem}

\begin{document}

\section{First Section}
\label{s:first}
\subsection{Introduction}
Here's some text.

\subsection{Explanation}
And some more.

\subsection{Exercises}
\begin{question}\label{q:first}
  Suppose I have ...
  \begin{enumerate}[label=\alph*)]
  \item What is ... \label{q:firstsub}
  \item Now compute ...
  \end{enumerate}
\end{question}

\begin{solution}
  \begin{enumerate}[label=\alph*)]
  \item Answer to first subpart
  \item Answer to second subpart
  \end{enumerate}
\end{solution}

\begin{question}\label{q:second}
  Now I have ... What is ...
\end{question}

\section{Second Section}
\label{s:second}

\subsection{Some text}
Here I have an example that refers back to Exercise
\ref{s:first}.\ref{q:first}. I {\em might} even want to refer to
Exercise \ref{s:first}.\ref{q:first}\ref{q:firstsub} although that is
less important.

\subsection{Exercises}
\begin{question}\label{q:later}
  And here's more...
  \begin{enumerate}[label=\alph*)]
  \item What is ...
  \item Now compute ...
  \end{enumerate}
\end{question}

And perhaps now I refer to Exercise \ref{s:second}.\ref{q:later}.

\end{document}

答案1

对于问题编号,您可以重新定义\thequestion(计数器使用的表示形式):在计数器和点前面question加上:section

\renewcommand\thequestion{\thesection.\arabic{question}}

完成此操作后,对于枚举,您可以使用键ref来提供所需的交叉引用格式,如下所示:

ref=\thequestion\alph*)

我将其添加为enumerate

\setlist[enumerate,1]{label=\alph*),ref=\thequestion\alph*)}

但是您可以对专用列表执行此操作,以防您想为其他enumerate环境设置其他格式。

完整示例:

\documentclass[11pt]{article}
\usepackage[counter-format=se.qu,counter-within=section]{exsheets}
\usepackage{enumitem}

\renewcommand\thequestion{\thesection.\arabic{question}}
\setlist[enumerate,1]{label=\alph*),ref=\thequestion\alph*)}

\begin{document}

\section{First Section}
\label{s:first}
\subsection{Introduction}
Here's some text.

\subsection{Explanation}
And some more.

\subsection{Exercises}
\begin{question}\label{q:first}
  Suppose I have ...
  \begin{enumerate}
  \item What is ... \label{q:firstsub}
  \item Now compute ...
  \end{enumerate}
\end{question}

\begin{solution}
  \begin{enumerate}
  \item Answer to first subpart
  \item Answer to second subpart
  \end{enumerate}
\end{solution}

\begin{question}\label{q:second}
  Now I have ... What is ...
\end{question}

\section{Second Section}
\label{s:second}

\subsection{Some text}
Here I have an example that refers back to Exercise~\ref{q:first}. I {\em might} even want to refer to
Exercise~\ref{q:firstsub} although that is
less important.

\subsection{Exercises}
\begin{question}\label{q:later}
  And here's more...
  \begin{enumerate}[label=\alph*)]
  \item What is ...
  \item Now compute ...
  \end{enumerate}
\end{question}

And perhaps now I refer to Exercise~\ref{q:later}.

\end{document}

在此处输入图片描述

相关内容