3

I am writing a book and in the end of each chapter I have a section with labeled problems that looks like this:

\chapter{Chapter 1}

Bla bla bla...

\section*{Problems:}
\begin{enumerate}
\item \label{ch1_pr1} Prove...
\item \label{ch1_pr2} Calculate...
\item \label{ch1_pr3} Fill the details in...
\end{enumerate}

The issue with this approach is that every problems' section is numbered exactly the same way in every chapter (1, 2, 3, 4, etc...) so if, say, in chapter four I want to cite the first problem in the first chapter I will get in my book just '1' (the number one), which will make it confusing, since it is not making any reference to the chapter the problem I am citing belongs to.

So my question is: How can I enumerate my problems so they take into account the chapter they belong to?

I was thinking something like 1.1, 1.2, 1.3, ... for the problems in chapter one, 2.1, 2.2, 2.3, ... for the problems in chapter two, etc. But I don't know how to do that.

Since I am not very skilled with Latex, I would ask for the solution to my problem to be as simple as possible.


Update: Here is some sample code so you can compile it and better understand what I need:

\documentclass[12pt,letterpaper]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\begin{document}

\chapter{First}

Bla bla bla...

\section*{Problems:}

\begin{enumerate}
\item \label{ch1_pr1} Prove...
\item \label{ch1_pr2} Calculate...
\item \label{ch1_pr3} Fill the details in...
\end{enumerate}

\chapter{Second}

Bla bla bla....

\section*{Problems:}

\begin{enumerate}
\item \label{ch2_pr1} Prove...
\item \label{ch2_pr2} Calculate...
\item \label{ch2_pr3} Fill the details in...
\end{enumerate}

\chapter{Third}

First problem in Chapter 1:~\ref{ch1_pr1}

First problem in Chapter 2:~\ref{ch2_pr1} \\

The issue: Different problems appear to be the same when cited!

\end{document}
2

Here's a similar solution using the enumitem package which makes it much easier to define new and customised lists. I also used problems for the environment name. Here, the label within the original problem set is just 1 or whatever, but the reference appears as 1.1 etc.

It is best not to use explicit numbers in your \label{}s in case you insert or remove items later. While LaTeX won't care two hoots, it tends to confuse human beings greatly if chap3_prf5 refers to the problem numbered 9 in chapter 2.

\documentclass{book}
\usepackage{enumitem}
\newlist{problems}{enumerate}{1}
\setlist[problems]{label={\arabic*.}, ref={\thechapter.\arabic*}}
\begin{document}
\chapter{Chapter 1}

Bla bla bla \dots

\section*{Problems:}
\begin{problems}
  \item \label{pr:intro_prove} Prove \dots
  \item \label{pr:intro_calc} Calculate \dots
  \item \label{pr:intro_details} Fill the details in \dots
\end{problems}

\chapter{Pethau Pellach}
Fel dywedwyd ym mhroblem \ref{pr:intro_calc} \dots
\end{document}

fel dywedwyd...

If you would prefer the chapter number to appear in the original label as well, change

\setlist[problems]{label={\arabic*.}, ref={\thechapter.\arabic*}}

to

\setlist[problems]{label={\thechapter.\arabic*}}

original labels, too

  • @cfr I am having some trouble implementing your solution: the problems do appear enumerated as I suggested (1.1, 1.2, 1.3, etc...) but when I try to reference them elsewhere in the book, they appear as before (1, 2, 3, etc...). – Carl Rojas Feb 24 '16 at 2:51
  • @CarlRojas Did you compile twice? – cfr Feb 24 '16 at 4:19
  • @cfr Yes, several times indeed! But there is something strange: when I try the code you gave me in the toy example I posted before it worked, but when I try it in the actual book it didn't. Any idea why? – Carl Rojas Feb 24 '16 at 15:59
  • @Bernard Obviously explains why you were quicker ;). – cfr Feb 24 '16 at 21:36
  • 1
    @cfr: B.t.w.: Didn't you add to the O.P.'s text some (possibly) fake Cymraeg? – Bernard Feb 24 '16 at 22:05
1

Here is a way to do it, defining a new list, based on enumerate, with some specifications, that I named problems which has two levels:

\documentclass{report}
\usepackage{geometry}
\usepackage{enumitem}
\usepackage{etoolbox}
\AtBeginEnvironment{enumerate}{\everymath{\displaystyle}}
\newlist{problems}{enumerate}{2}
\setlist[problems]{wide=0pt}
\setlist[problems, 1]{label =\thechapter.\arabic*, font=\bfseries, wide=0pt}
\setlist[problems,2]{label =(\alph*), wide =0.5em, topsep=2pt, itemsep =2pt}

\begin{document}

\chapter{Chapter 1}

Bla bla bla...

\section*{Problems:}

\begin{problems}
  \item \label{ch1_pr1} Prove...
  \begin{problems}
    \item A first question
    \item Another silly question. A silly question. A silly question. A silly question. A silly question. A silly question. A silly question. A silly question. A silly question.
  \end{problems}
  \item \label{ch1_pr2} Calculate...
  \item \label{ch1_pr3} Fill the details in...Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{problems}

\chapter{Chapter 2}

Bla bla bla...

\section*{Problems:}

\begin{problems}
  \item \label{ch1_pr1} Prove...
  \begin{problems}
    \item A first question
    \item Another silly question. A silly question. A silly question. A silly question. A silly question. A silly question. A silly question. A silly question. A silly question.
  \end{problems}
  \item \label{ch1_pr2} Calculate...
  \item \label{ch1_pr3} Fill the details in...Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\end{problems}

\end{document} 

enter image description here

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.