2

I am writing a book in LaTeX in which I label problems m.n for Chapter m, problem n (for example, problem 6.10 is the 10th problem in Chapter 6). I am using the declaration

\renewcommand{\theenumi}{\arabic{enumi}}
\renewcommand{\labelenumi}{\thechapter.\theenumi}

and this correctly prints problem labels in the enumerate environment where the problems are listed. However, when I refer to a problem elsewhere, it only prints the problem number (e.g., "see Problem 6.10" is written "see Problem 10"). Is there a global fix for this?

1

2 Answers 2

2

As Christian suggests, using the enumitem package is probably the best approach. I would go one step further than the answer he refers to and define a new problems environment for your problems. To do what you want using enumitem is as simple as:

\newlist{problems}{enumerate}{1}% or 2 or 3 if you want to nest
\setlist[problems]{label=\thechapter.\arabic*, 
                   ref=Problem \thechapter.\arabic*
}

Here I am assuming that you want \ref{...} to print something like Problem 1.2. If you just want it to print 1.2 then omit the ref=.... For more details consult the very readable enumitem manual.

In fact, as shown below, I would also have the problems environment automatically add a heading for the problems, which you can do using the before= option from. enumitem. Below I have used \section{...} but perhaps \section*{...} or \subsection{...} etc would work better for you.

Here a full minimal working example:

\documentclass{book}
\usepackage{enumitem}

\newlist{problems}{enumerate}{1}% or 2 or 3 if you want to nest
\setlist[problems]{label=\thechapter.\arabic*,
                   ref=Problem \thechapter.\arabic*,
                   before={\section{Problems for Chapter \thechapter}}
}

\begin{document}

\chapter{First chapter}

\begin{problems}
  \item Is the Riemann hypothesis true? \label{Riemann}
  \item Find the first counter-example to the twin primes conjecture
  \label{twins}
\end{problems}

Actually, \ref{Riemann} and \ref{twins} are quite hard, so allow at
least an extra week.
\end{document}

For completeness, this produces:

enter image description here

1

Referencing counters uses \the<cntr> as it's reference content. So, instead, you should redefine \theenumi to fully contain your representation (as it will be set and therefore referenced):

enter image description here

\documentclass{book}

\newenvironment{questions}
  {\renewcommand{\theenumi}{\thechapter.\arabic{enumi}}%
   \begin{enumerate}}
  {\end{enumerate}}

\begin{document}

\setcounter{chapter}{9}% Just for this example

\chapter{Questions}

See questions \ref{q:first}--\ref{q:last}.

\begin{questions}
  \item \label{q:first}
  First question

  \item
  Second question

  \item
  Third question

  \item \label{q:last}
  Last question
\end{questions}

\end{document}

The above example redefines \theenumi as part of a new questions environment. This allows you to localise the change of definition without it affecting other enumerate environments (if they're used).

You must log in to answer this question.

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