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
:
Since in the comments an exsheets
solution for such a layout was welcomed here it is... the usage is quite different from the exercise
package, though...
The solution contains of several steps:
Wrap KOMA-Script's addmargin
environment around the question
environment with the help of etoolbox
's \AtBeginEnvironment
and \AtEndEnvironment
. This gets the question bodies indented by the specified margin (3em
in the example below). The addmargin
environment is provided by the scrextend
package so it can be used with other classes, too.
Declare a new heading instance inspired by margin-nr
instance described in the exsheets
manual which uses the same margin as set by the addmargin
environment (3em
in the example below) to place the question number aligned with the text margin.
Set up exsheets
to use the new instance and add some options for in-section numbering.
This is how the document from the code below looks like:
\documentclass{article}
\usepackage{scrextend}% not needed with a KOMA-Script class, provides the
% `addmargin' environment
\usepackage[load-headings]{exsheets}
\DeclareInstance{exsheets-heading}{mylist}{default}{
runin = true ,
attach = {
main[l,vc]number[l,vc](-3em,0pt) ; % 3em = indent of question body
main[r,vc]points[l,vc](\linewidth+\marginparsep,0pt)
}
}
\SetupExSheets{
headings = mylist , % use the new headings instance
headings-format = \normalfont ,
counter-format = se.qu ,
counter-within = section
}
\usepackage{etoolbox}
% 3em = indent of question body :
\AtBeginEnvironment{question}{\addmargin[3em]{0em}}
\AtEndEnvironment{question}{\endaddmargin}
\usepackage{lipsum}
\begin{document}
\setcounter{section}{10}
\section*{Exercises}
\subsection*{Exercises to section \thesection}
\begin{question}
\lipsum[4]
\end{question}
\begin{question}
\lipsum[6]
\end{question}
\begin{question}
\lipsum[10]
\end{question}
\end{document}
Best Answer
Maybe you would like to number to exercises within chapters.
I've used xassoccnt to print the total number of exercises.
I've modified
\ExerciseHeader
and\AnswerHeader
to print the Chapter number and name before its exercises when you ship out them.