使用問題計數器對出現在文件末尾的解決方案中的方程式進行編號

使用問題計數器對出現在文件末尾的解決方案中的方程式進行編號

我用來exsheets寫問題集。我想按方程式所屬的問題對方程式進行編號。所以我用\numberwithin{equation}{question}.

這對於出現在問題本身中的方程式很有效,但不適用於解決方案(我在最後列印)。

\documentclass{article}

\usepackage{amsmath}
\usepackage{exsheets}

\numberwithin{equation}{question}

\begin{document}

\begin{question}
First Question
\begin{equation}
a^2 + b^2 = c^2
\end{equation}
\end{question}
\begin{solution}
    \begin{equation}
        E = m c^2
    \end{equation}
\end{solution}

\begin{question}
Second Question
\end{question}

\section*{Answers}%
\printsolutions%

\end{document}

在此輸入影像描述

我期望「a^2+b^2=c^2」編號為 1.2。

所有解方程式都使用最後一個問題的編號作為其編號。如何在解決方案中使用適當的問題編號?

答案1

一個簡單的解決方法是添加標籤;如果您只使用equation. ,這可能會自動實現。

\documentclass{article}

\usepackage{amsmath}
\usepackage{exsheets}

\numberwithin{equation}{question}
\NewDocumentCommand{\TAG}{m}{\label{#1}}

\begin{document}

\begin{question}
First Question
\begin{equation}
a^2 + b^2 = c^2 \TAG{A}
\end{equation}
\end{question}
\begin{solution}
    \begin{equation}
        E = m c^2 \TAG{A}
    \end{equation}
\end{solution}

\begin{question}
Second Question
\end{question}

\section*{Answers}
\RenewDocumentCommand{\TAG}{m}{\tag{\ref{#1}}}
\printsolutions

\end{document}

在此輸入影像描述

相關內容