GeneralReferences to sections in a different chapter

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Addle
Posts: 4
Joined: Sun Jul 08, 2012 7:13 pm

References to sections in a different chapter

Post by Addle »

Very basic question about references and labels, but I'm unable to find the answer. I'm working with a document with amsbook documentclass. It doesn't matter too much, but I use cleveref. When I make a reference to a section in a different chapter, it gives only the section number. This is obviously misleading to a reader, who has no way of knowing what chapter the referenced section is in. What am I doing wrong?

Minimal example:

Code: Select all

\documentclass{amsbook}
\usepackage{cleveref}
\begin{document}

\chapter{One}
\section{Section 1}
We'll be covering some interesting topics in \cref{sec:Ch2Sec2}

\section{Section 2}
There's nothing interesting here.

\chapter{Two}
\section{Section 1}
Later, it will be \cref{sec:Ch2Sec2}

\section{Section 2} \label{sec:Ch2Sec2}
Very interesting stuff.
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

References to sections in a different chapter

Post by Ijon Tichy »

It's a decision of AMS to have section numbers without chapter prefix numbers and to reference sections also without the chapter numbers. With, e.g., the standard classes sections would be numbered chapter.section and therefore references would also be with the chapter number.

However, since 2019-10-01 LaTeX provides \labelformat to define the format of the counter reference. You can use \labelformat{section}{\thechapter.\thesection} to add the chapter number and a dot as prefix to the references.
\documentclass{amsbook}
\usepackage{cleveref}
\labelformat{section}{\thechapter.#1}% use prefix "\thechapter." for
                                     % references to sections
\begin{document}

\chapter{One}
\section{Section 1}
We'll be covering some interesting topics in \cref{sec:Ch2Sec2}

\section{Section 2}
There's nothing interesting here.

\chapter{Two}
\section{Section 1}
Later, it will be \cref{sec:Ch2Sec2}

\section{Section 2} \label{sec:Ch2Sec2}
Very interesting stuff.
\end{document}
This works with and without cleveref. There may be other cleveref specific solutions, but I prefer this one, that still works, if I don't use cleveref.

If you'd get an error about undefined \labelformat you should update LaTeX. However, there is also an old method to do the same:

Code: Select all

\makeatletter
\def\p@section{\thechapter.}
\makeatother
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Addle
Posts: 4
Joined: Sun Jul 08, 2012 7:13 pm

References to sections in a different chapter

Post by Addle »

Thank you for the reply. This is a workable solution, though perhaps not ideal because it means the numbering of the references is different from the numbering of the sections. I am debating between:
a) Use your solution as it stands,
b) Do some fancy footwork, if I can figure out how, to parse the label x.y and format references as "section y" if it's referenced in chapter x, and "chapter x, section y" if it's not. Perhaps cleveref can make this easier. (I'm not sure.)
c) Modify the way sections are numbered in the amsbook documentstyle.
Post Reply