Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm typing up some assignments with the basic structure

Problem problem number


and I'm not really satisfied with the LaTeX source I'm making. For example

\section*{Problem 1}
In order to solve $a^2+b^2 = c^2$ ...

This solution is not very good since it doesn't use the automatic counters and though the assignments are short I might have longer ones later and need a table of contents.

Now, problems in my context are logical sections of my documents, and so \section makes sense. Would some type of new command say \problem make more sense?

share|improve this question
You'll find more LaTeX questions and answers on Stack Overflow than super user: . See meta questions… and… for some discussion on where such questions are most appropriate. – dmckee Oct 21 '09 at 14:47
It didn't feel appropriate on Stack Overflow as this was a more mathy homework assignment and LaTeX isn't very programmy. – Flame Oct 21 '09 at 19:08
It is not perfectly clear, but there seem to be more LaTeXers on SO than SU, that's all... – dmckee Oct 21 '09 at 20:12
up vote 2 down vote accepted

I found this example. It's not exactly what you want, but if you look up using counters and the newcommand and renewcommand definitions, you should be able to do exactly what you want, which wasn't totally clear to me.



\newcommand{\problem}{\refstepcounter{problem}{\vspace{2\baselineskip}\noindent\large \bfseries Problem~\arabic{set}.\arabic{problem}}\\}

\textit{Sum-product algorithm:}  Consider the sum-product\ldots.

\textit{Max-marginals:} Consider the max-marginals\ldots.

Demonstraction of \verb"\stepcounter"

Counter increments can be negative!

share|improve this answer

I use the exam document class for this task. A basic document then looks like this:

\firstpageheader{}{}{\bf\large Name \\ Class \\ Assignment \\ Due Date}
\runningheader{Name}{Class Assignment}{Due Date}

    This is the question.

    This is the solution to the question.


Prior to discovering the exam class, I used the hmcpset document class from the mathematics department at Harvey Mudd College.

share|improve this answer
+1 I like your answer better than mine ;-) – DaveParillo Oct 21 '09 at 19:58
+1 for mentioning Harvey Mudd College :^) – Broseph Jun 24 '14 at 16:21

I would suggest using enumerate to organize problems and use sections to group them. For example:

The ``enumerate'' environment numbers the list elements, like this.

Items in a list can contain multiple paragraphs.
These paragraphs are appropriately spaced and indented according to their
position in the list.
  \item The ``itemize'' environment sets off list items with ``bullets'',
like this. Finally, the ``description'' environment lets you put your own
    \item[A] label on each item, like this ``A''.
    \item[If the label is long,] the first line of the item text will
be spaced over to the right as needed.

Taken from LaTeX by Example

Doing this gives you way more flexibility structuring the details of your individual assignments - for example you can enumerate as deeply as you need, but can only take sections to 3 levels.

share|improve this answer

For this kind of thing, I would probably use the theorem package. Using it, you can define a theorem-like environment like this:


Here, the optional argument [chapter] says that numbering is to be performed per-chapter, so you get numbering like 1.1, 1.2 in the first chapter, 2.1 in the second chapter and so on. If you just want sequential numbering throughout the document, leave out that argument altogether.

And you would use it like this:

  ... text here

Of course, you would want to give it a more descriptive label than just prob:1.

Also, the default typesetting puts the text in italics. You can change that by replacing the definition with something like


I've encased the font change in {} so that it only affects this environment definition and not any others you might have.

share|improve this answer
I used to do this; then I discovered document classes designed for this task. – las3rjock Oct 21 '09 at 18:27

One way to do it is to use the equation environment:

a^2 + b^2 = c^2

In order to solve \eqref{myeq} ...

That gives you numbered equations and a way to refer to them.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .