枚举模式:1、1、2、2、3、3、... 等

枚举模式:1、1、2、2、3、3、... 等

这是答案有时在测试中,有时在答案文件中

我采用了最佳答案所建议的内容,并用 和 包围每个问题和答案,\begin{filecontents}{some title}\end{filecontents}给出了类似于此处的代码:

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{enumitem}

\begin{document}
\begin{center}
\textbf{Mock Exam}
\end{center}

\usepackage{filecontents}
\begin{filecontents}{question-01}
\begin{enumerate}[resume]
\item Here's a question. \par
\begin{enumerate}[label=(\Alph*)]
\item Option A
\item Option B
\item Option C
\item Option D
\item Option E
\end{enumerate}
\end{filecontents}

\begin{filecontents}{question-02}
\pagebreak
\begin{enumerate}[resume]
\item Here's another question.\par
\begin{enumerate}[label=(\Alph*)]
\item Option A
\item Option B
\item Option C
\item Option D
\item Option E
\end{enumerate}
\end{filecontents}

\input{question-01}
\input{question-02}
\end{document}

这适用于问题编号(即,它为问题分配了正确的数字),但是一旦我引入解决方案,会发生什么?如果我添加此代码:

\begin{filecontents}{solution-01}
\begin{enumerate}[resume]
\item (A)\par

\vspace{0.2cm}
-Some stuff telling you why the answer is (A)-\par
\end{enumerate}
\end{filecontents}

\begin{filecontents}{solution-02}
\begin{enumerate}[resume]
\item (C)\par

\vspace{0.2cm}
-Some stuff telling you why the answer is (C)-\par
\end{enumerate}
\end{filecontents}

然后插入解决方案需要去的地方,然后我就会得到

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{enumitem}

\begin{document}
\begin{center}
\textbf{Mock Exam}
\end{center}

\usepackage{filecontents}
\begin{filecontents}{question-01}
\begin{enumerate}[resume]
\item Here's a question. \par
\begin{enumerate}[label=(\Alph*)]
\item Option A
\item Option B
\item Option C
\item Option D
\item Option E
\end{enumerate}
\end{filecontents}

\begin{filecontents}{question-02}
\pagebreak
\begin{enumerate}[resume]
\item Here's another question.\par
\begin{enumerate}[label=(\Alph*)]
\item Option A
\item Option B
\item Option C
\item Option D
\item Option E
\end{enumerate}
\end{filecontents}

\begin{filecontents}{solution-01}
\begin{enumerate}[resume]
\item (A)\par

\vspace{0.2cm}
-Some stuff telling you why the answer is (A)-\par
\end{enumerate}
\end{filecontents}

\begin{filecontents}{solution-02}
\begin{enumerate}[resume]
\item (C)\par

\vspace{0.2cm}
-Some stuff telling you why the answer is (C)-\par
\end{enumerate}
\end{filecontents}

\input{question-01}
\input{solution-01}
\input{question-02}
\input{solution-02}
\end{document}

不幸的是这将给出以下编号:

1. 问题 1
2. 解决方案 1
3. 问题 2
4. 解决方案 2

我需要编号为

1. 问题 1
1. 解决方案 1
2. 问题 2
2. 解决方案 2

有任何想法吗?

仅供参考:我不想为这些问题和解决方案分配硬值 - 它们可能需要被移动。

答案1

对问题和解决方案使用专用环境。使用enumitems\newlist和很容易\setlist。这有一个额外的好处:你的代码将具有更多的语义标记:

\newlist{question}{enumerate}{1}
\newlist{solution}{enumerate}{1}
\setlist[question,solution]{label=\arabic*.}

对于您的选择列表,我还将定义一个新列表:

\newlist{choices}{enumerate}{1}
\setlist[choices]{label=(\Alph*)}

\pagebreak一个完整的例子(为了得到一个更短的例子我删除了):

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}

\usepackage{enumitem}
\newlist{choices}{enumerate}{1}
\setlist[choices]{label=(\Alph*)}

\newlist{question}{enumerate}{1}
\newlist{solution}{enumerate}{1}
\setlist[question,solution]{label=\arabic*.}

\usepackage{filecontents}
\begin{filecontents}{question-01}
\begin{question}[resume]
  \item Here's a question.
  \begin{choices}
    \item Option A
    \item Option B
    \item Option C
    \item Option D
    \item Option E
  \end{choices}
\end{question}
\end{filecontents}

\begin{filecontents}{question-02}
\begin{question}[resume]
  \item Here's another question.
  \begin{choices}
    \item Option A
    \item Option B
    \item Option C
    \item Option D
    \item Option E
  \end{choices}
\end{question}
\end{filecontents}

\begin{filecontents}{solution-01}
\begin{solution}[resume]
  \item (A)\par\medskip
  -Some stuff telling you why the answer is (A)-
\end{solution}
\end{filecontents}

\begin{filecontents}{solution-02}
\begin{solution}[resume]
  \item (C)\par\medskip
  -Some stuff telling you why the answer is (C)-
\end{solution}
\end{filecontents}

\begin{document}
\begin{center}
\textbf{Mock Exam}
\end{center}

\input{question-01}
\input{solution-01}
\input{question-02}
\input{solution-02}
\end{document}

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}

\usepackage[load-headings]{exsheets}
\SetupExSheets{
  headings = runin ,
  solution/print = true
}

\usepackage{enumitem}
\newlist{choices}{enumerate}{1}
\setlist[choices]{label=(\Alph*)}

\begin{document}

在此处输入图片描述

话虽如此,我建议使用专门的包来处理问题和答案,例如exsheets为了这:

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}

\usepackage[load-headings]{exsheets}
\SetupExSheets{
  headings = runin-nr ,
  headings-format = \normalfont ,
  solution/print = true
}

\usepackage{enumitem}
\newlist{choices}{enumerate}{1}
\setlist[choices]{label=(\Alph*)}

\begin{document}

\begin{center}
  \bfseries Mock Exam
\end{center}

\begin{question}
  Here's a question.
  \begin{choices}
    \item Option A
    \item Option B
    \item Option C
    \item Option D
    \item Option E
  \end{choices}
\end{question}
\begin{solution}
  (A) \par\medskip
  Some stuff telling you why the answer is (A).
\end{solution}

\begin{question}
  Here's another question.
  \begin{choices}
    \item Option A
    \item Option B
    \item Option C
    \item Option D
    \item Option E
  \end{choices}
\end{question}
\begin{solution}
  (C) \par\medskip
  Some stuff telling you why the answer is (C).
\end{solution}

\end{document}

在此处输入图片描述

相关内容