1

This is a follow-up question to answers sometimes in test, sometimes in answer file.

I went with what the best answer suggested and surrounded each question and answer by \begin{filecontents}{some title} and \end{filecontents}, giving a code similar to this here:

\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}

This works for question numbering (i.e, it assigns the questions the correct numbers), but what will happen once I bring in the solutions? If I add this code in:

\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}

and then insert where the solutions need to go, then I'll get

\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}

which is unfortunately going to give the following numbering:

1. Question 1
2. Solution 1
3. Question 2
4. Solution 2

I need the numbering to be

1. Question 1
1. Solution 1
2. Question 2
2. Solution 2

Any ideas?

FYI: I do not want to assign these questions and solutions hard values - they may need to be moved around.

Clarinetist
  • 1,550
  • I'd use a dedicated package like exsheets for this... – cgnieder Jul 14 '14 at 19:47
  • From the exsheets document: "On the other hand ExSheets doesn’t – and probably won’t – offer a real possibility for creating multiple choice questions. As a fact it doesn’t provide many (if any) means to specify the type of question or the structure. If these are your needs take a look at examdesign [Ale01], for example. Or exploit the possibilities enumitem [Bez11] gives you." examdesign, at a first glance, isn't meant to display exam solutions. – Clarinetist Jul 14 '14 at 19:53
  • As a note, I'm not a professor (I work for a study materials company), so I don't have much flexibility as to how I can design the question and solution files. – Clarinetist Jul 14 '14 at 19:53
  • you're already using enumitem. It can be used with exsheets without problems. The comment means that exsheets does not define own environments for multiple choice lists like e.g. the exam class does. OTOH exsheets has very customizable question headings so it's possible to create a lot of different layouts with it. – cgnieder Jul 14 '14 at 19:58

1 Answers1

2

Use dedicated environments for both questions and solutions. This is easy by using enumitems \newlist and \setlist. This has an extra bonus: your code will have more semantic markup:

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

For your list of choices I'd also define a new list:

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

A complete example (where I've removed the \pagebreak in order to get a shorter example):

\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}

enter image description here

That being said I'd suggest to use a dedicated package for questions and answers like exsheets for this:

\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}

enter image description here

cgnieder
  • 66,645
  • Yep, you convinced me. exsheets is very nice, and the documentation actually explains it well! I'll try this out and let you know how it goes. Thank you! – Clarinetist Jul 14 '14 at 20:17
  • If you want solutions and questions separated then remove the line solution/print = true in my code and add \printsolutions where you want the solutions printed (as long as it is after the questions). Section 11 Printing the solutions has the details. – cgnieder Jul 14 '14 at 20:21
  • @cgneider - Thank you for telling me about this package! It's a lot easier than I thought it would be! I only have one question - is there any way I can customize the enumerate number? In a previous project, we did \begin{enumerate}[label=\Large\textbf{\arabic*.}] to number the questions. Thank you again! – Clarinetist Jul 14 '14 at 20:43
  • 1
    You mean the number of the questions? Yes. Default is bold which I disabled in my example with headings-format = \normalfont. Default is \normalsize\bfseries so you probably want headings-format = \Large\bfseries – cgnieder Jul 14 '14 at 20:50