5

I'm trying to create an environment for homework assignment problems. Most of these problems consists of itemized questions about an introductory paragraph.

I know I can write a problem environment and put an enumerate environment inside it, but I really want is to be able to write something like this:

\begin{problem}
John was born in 1992.

\item How old is John?
\item How old will John be next year?
\end{problem}

Ideally, I should also allow \item[1,0] or something similar to specify the question value. The output should be like:

Question 1. John was born in 1992.

a) How old is John?

b) How old will John be next year?

Is there any enumerating package which supports this behavior? If not, how could I do it manually?

  • What should \item[1,0] translate to in your output? – Werner Apr 7 '15 at 18:33
  • 3
    There are some packages devoted to this kind of stuff, namely exsheets, probsoln or the exam class. – Johannes_B Apr 7 '15 at 18:34
  • @Werner "a) (1,0 points) How old is John?" for example, although the format is not the biggest issue. – villasv Apr 7 '15 at 18:38
4

As Johannes_B points out, there are specialized document classes and packages devoted to this. But if you want something simpler...

\documentclass{article}
\usepackage{enumitem}
\newcounter{question}
\newenvironment{problem}
{\stepcounter{question}\begin{enumerate}[label=\alph*.]
\setbox0=\hbox{Question \thequestion.}%
\edef\tmplen{\the\wd0}%
\def\tmp{\makebox[2em][l]{\box0}}%
\item[\tmp]\hspace{\dimexpr\tmplen-2em\relax}}
{\end{enumerate}}
\usepackage{lipsum}
\begin{document}
\lipsum[4]
\begin{problem}
John was born in 1992.

\item How old is John?
\item How old will John be next year?
\end{problem}

\begin{problem}
Mary was born in 1995.

\item How old is Mary?
\item How much older than Mary is John?
\end{problem}

\end{document}

enter image description here

  • Amazing, thak you very much. I'll take a look at the exam class too. – villasv Apr 7 '15 at 19:09

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.