I managed to get it to work using the ExerciseList environment:
\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{mhchem}
\usepackage[lastexercise]{exercise}
\begin{document}
\section{Naming of Chemical Compounds - A ``DIY'' Tutorial}
\begin{ExerciseList}
\Exercise[title=DIY]
\ExePart{Question 1}
\Question{What is the symbol for copper?}
\Answer{\ce{Cu}}
\end{ExerciseList}
\end{document}
Use of \ExePart or redefinition of \QuestionNB
That said, you shouldn't need the \ExePart
just to print "Question 1". It might be better to redefine \QuestionNB
instead, like this:
\renewcommand{\QuestionNB}{Question~\arabic{Question}.\ }
Theorically, that should do what you want to achieve, although in practice, it's kind of a mess. I feel the reason is that the label is hardcoded in the package, and without a variable. This can however be "fixed" by resetting \QuestionIndent
:
\setlength{\QuestionIndent}{7em}
So your example becomes:
\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{mhchem}
\usepackage[lastexercise]{exercise}
\begin{document}
\section{Naming of Chemical Compounds - A ``DIY'' Tutorial}
\renewcommand{\QuestionNB}{Question~\arabic{Question}.\ }
\setlength{\QuestionIndent}{7em}
\begin{ExerciseList}
\Exercise[title=DIY]
\Question{What is the symbol for copper?}
\Answer{\ce{Cu}}
\end{ExerciseList}
\end{document}
which works for me (although I would personally find it nicer to put questions on the next line -- note: I'm not using the mhchem
package):
After playing a bit with more Questions/Answers, I do think it's missing a linebreak somewhere:
I'm also not very sure of the spacing: answers end up being closer to the next question than to the question they relate to...
Exercise title
In fact, it seems the problem with the linebreak comes from the fact that you're using \Exercise[title=DIY]
instead of simply \Exercise{DIY}
, which defines the exercise name. When I change this:
\documentclass[12pt]{article}
\usepackage[a4paper]{geometry}
\usepackage{mhchem}
\usepackage[lastexercise]{exercise}
\begin{document}
\section{Naming of Chemical Compounds - A ``DIY'' Tutorial}
\renewcommand{\QuestionNB}{Question~\arabic{Question}.\ }
\setlength{\QuestionIndent}{7em}
\begin{ExerciseList}
\Exercise{DIY}
\Question{What is the symbol for copper?}
\Answer{\ce{Cu}}
\Question{What is the symbol for aluminum?}
\Answer{\ce{Al}}
\Question{What is the symbol for iron?}
\Answer{\ce{Fe}}
\end{ExerciseList}
\end{document}
I get a linebreak:
and it is not necessary anymore to redefine \QuestionIndent
:
The exercise
package has a specific way to manage the label.
See the package documentation subsection 2.4.
\documentclass{article}
\usepackage{hyperref}% you must load it before the exercise package
\usepackage[answerdelayed]{exercise}
\begin{document}
\begin{Exercise}[label={mylabel}]
What is the value of 2+5? (To see the answer click here: \refAnswer{\ExerciseLabel})
\end{Exercise}
\begin{Answer}[ref=\ExerciseLabel]
7
\end{Answer}
rest of the document
\newpage % I've added a new page only to clearly show the hyperlink. Of course, you don't need it in your document.
\shipoutAnswer
\end{document}
Best Answer
There are two parts to this answer:
After redefining the macros
\ExerciseHeader
and\AnswerHeader
, the indentation of the the headlines equals the usual indentation of the text. You can set this to zero with:In the code of the
exercise
package, there is a hard-coded\hspace{.66em}
at the start of theExercise
body. To neutralize it, you can redefine\AtBeginExercise
:So your full header section on the style of the
Exercise
andAnswer
could look like this:Update: You might be right, there is still too much space before the exercise title, and I'm not one hundred percent sure about the space in front of the exercise body. So with changing "Aufgabe" to "Hausaufgabe" and "Gegeben ist ein Würfel" to "Es ist ein Würfel gegeben" (to have straigth lines at the left to compare indentation more easily), I find this configuration satisfying to my eye: