Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to have problems be consecutively numbered throughout a book, irrespective of the chapters and sections where they appear.

E.g.

Chapter 1
[Text]
1. Some problem
Section 1
2. Some problem
[Text]
Section 2
3. Some problem
Etc

What's the easiest way to do this?

share|improve this question
    
Assuming you will want to typeset solutions as well, you can combine @Werner's solution with code from the answers package: ctan.org/pkg/answers –  cmhughes Sep 12 '11 at 4:26
1  
Also of interest (without the "counter within" part), might be: Create odd-numbered answers, or all answers –  Werner Sep 12 '11 at 4:47
add comment

4 Answers 4

up vote 5 down vote accepted

You could make your own environment that works on a counter. It allows you freedom to manage the formatting of the problem typesetting as well. Here's an example:

\documentclass{book}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newcounter{problem}
\newenvironment{problem}{%
  \refstepcounter{problem}% For correct referencing
  \textbf{Problem~\theproblem.}\ 
}{\par}

\begin{document}

\chapter{First chapter} \lipsum[1]
\section{first section} \lipsum[2]
\begin{problem}
Here is a very interesting problem that you can do. \label{problem1}
\end{problem}
\lipsum[3]
\section{Second section} \lipsum[4]
\begin{problem}
Wow, have you seen this problem? \label{problem2}
\end{problem}
\section{Last section} \lipsum[5]
\begin{problem}
This is the final problem of the book. It is actually much harder than
Problems~\ref{problem1} and~\ref{problem2} combined.
\end{problem}
\lipsum[7]

\end{document}

The lipsum package provides dummy text used to fill the "book". In the above example, the problem is typeset as a paragraph in the form:

Problem 1. blah blah blah

...

Problem 2. blah blah blah

...

Since the counter is not tied to any other counter, it runs through the book without resetting. Referencing is also possible using labels in the traditional way.

Problems

share|improve this answer
    
Thanks, this is exactly what I was looking for. –  Ornik Sep 14 '11 at 3:54
add comment

A lot depends on how you are defining the problem environment. If you are creating your own environment, then define the relevant counter to not depend on anything.

If your problem environment is being created by, e.g. on of the theorem packages (such as amsthm) you can usually specify the relations among the counters when you define the theorem type.

Finally, if you are using a package that defines its own problem environment that automatically determines the counter dependencies, you can use the chngcntr package to easily control the numbering relations among existing counters.

share|improve this answer
add comment

Use the enumitem package with which you can easily resume a list.

\documentclass[12pt]{book}
\usepackage{enumitem}
\newcounter{ProblemNumber}%
\newenvironment{Problem}{%
    \begin{enumerate}\setcounter{enumi}{\theProblemNumber}
}{%
   \setcounter{ProblemNumber}{\value{enumi}}
   \end{enumerate}
}%

\begin{document}
\chapter{Chapter One}
Text
\begin{Problem}
  \item Some Problem
\end{Problem}
\section{Section One}
Some Text
\begin{Problem}
  \item Some Problem
\end{Problem}
\section{Section Two}
\begin{Problem}
  \item Some Problem
\end{Problem}
\end{document} 
share|improve this answer
    
This isn't an ideal way to do things, since you may need other enumerations in the document. It's better to have a specific problem environment. –  Alan Munn Sep 12 '11 at 4:43
    
Duh!!! Thanks Alan. I have adapted the previous solution so that you can still use other enumerations which won't effect this list. –  Peter Grill Sep 12 '11 at 5:08
add comment

There are at least three packages -- theorem, ntheorem, and amsthm -- that can create numbered environments with various styles for the fonts of the headers and the body of the environment, various amounts of vertical skip before and after the environment, etc. While these packages were originally created for writers who need environments for theorems, corollaries, and the like, their code is really applicable to a wide range of situations. The MWE below uses the ntheorem package. Happy TeXing!

\documentclass{article}
\usepackage{ntheorem,lipsum}
\theorembodyfont{\slshape}
\newtheorem{problem}{Problem}
\begin{document}
\section{First section}
\lipsum[2]
\begin{problem}[Apollo 13]\label{prob:houston}
Houston, we have a problem.
\end{problem}
\lipsum[2]
\section{Next section}
\lipsum[2]
\begin{problem}[Cool Terminator] \label{prob:term}
No problemo.
\end{problem}
\section{Still another section}
As might be noted from Problems \ref{prob:houston} 
and \ref{prob:term}, \ldots
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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