3

I am typesetting some exercises with the following structure,

Exercise 1
Some introductory text.
1.1 The first question?
1.2 The second question?

Using the exercise package I can accomplish this in the following way,

\begin{Exercise}
    Some introductory text.
    \Question The first question?
    \Question The second question?
\end{Exercise}

Now I want to type an answer to each question. The only way I found to do this is by setting the numbering myself in the answer,

\begin{Answer}[number=1.1]
    The answer to Question 1.1.
\end{Answer}
\begin{Answer}[number=1.2]
    The answer to Question 1.2.
\end{Answer}

which will eventually fail when the order of exercises/questions changes.

What is the right way of doing this?

How can I link an individual answer to each of the questions?

2

You can use the ref=<ref> or number=\ref{<ref>} key when you \label the questions of interest:

enter image description here

\documentclass{article}
\usepackage{exercise}% http://ctan.org/pkg/exercise
\begin{document}
\begin{Exercise}
    Some introductory text.
    \Question \label{first}The first question?
    \Question \label{second}The second question?
\end{Exercise}

\begin{Answer}[ref=first]
    The answer to Question~\ref{first}.
\end{Answer}
\begin{Answer}[number=\ref{second}]
    The answer to Question~\ref{second}.
\end{Answer}
\end{document}
2

As alternative a quite elegant solution by the excellent »exsheets« package.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[load-tasks=true]{exsheets}

\settasks{
  counter-format=qu.tsk,
  item-indent=3em,
  label-width=2em
}

\begin{document}
  \section{Foo}
  \begin{question}\label{qu:twopart}
    Some introductory text.
    \begin{tasks}
      \task The first question?\label{qu-1:twopart}
      \task The second question?\label{qu-2:twopart}
    \end{tasks}
  \end{question}

  \begin{solution}
    \begin{tasks}
      \task Solution to question \ref{qu-1:twopart}.
      \task Solution to question \ref{qu-2:twopart}.
    \end{tasks}
  \end{solution}

  \printsolutions
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.