GeneralIssue when cross-referencing with short chapter names

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Loupiote3
Posts: 4
Joined: Tue Jul 31, 2018 2:47 pm

Issue when cross-referencing with short chapter names

Post by Loupiote3 »

Hi all,

Sorry if this already has an answer somewhere, I have been pulling my hair out trying to solve this for a while now (beginner alert).

I am writing a thesis in the book format, and some of my chapters have very long titles. Accordingly, I have given them short titles so that the headers do not overflow, like such:

\chapter[short title]{Awfully long title that won't fit in a header}

So far, so good.
Now, I am wanting to reference some of my chapters in the text, like this:

This is adressed at length in Chapter 2.

I tried labelling the chapter in question, and calling the reference in the text using \ref{label}.
Now here is my problem: even though I introduced the label straight after the \chapter command, like this:

\chapter[short title]{Awfully long title that won't fit in a header}
\label{ch:chaptername}

The reference in the text appears as "This is adressed at length in Chapter 2.5".
There are 5 sections in chapter 2, but I want to reference the whole chapter, not section 2.5.

I have noticed that this does not happen if I remove the short title for the chapter, so that this code allows me to reference Chapter 2 just fine:

\chapter{Awfully long title that won't fit in a header}
\label{ch:chaptername}

\ref{ch:chaptername}

When I add the short title, the backslash in front of "chapter" does not appear in bold anymore, and it seems like the counter gets upset.

Has anyone had that problem and did you manage to solve it?

Many thanks in advance!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Issue when cross-referencing with short chapter names

Post by Johannes_B »

Welcome to the forum.

The behaviour you describe isn't normal. Something in your document, most likely in the preamble causes this problem. We don't know your preamble, though. Can you post a minimal working example, meaning your complete preamble and a test chapter? Please copy the code first to a new directory and see if it is compiling and showing the behaviour.

Regarding the bold thing: This is just syntax highlighting done by the editor software.

Code: Select all

\documentclass{book}
\usepackage{scrlayer-scrpage}
\usepackage{mwe}
\begin{document}
\chapter[MR]{Manta Ray}
\label{ch:mantarey}
\blindtext see \ref{ch:mantarey}
\section{Taxonomy}
\blindtext[10]
\chapter{Mobula}
\blindtext
\section{Life style}
\blindtext[10]
\end{document}

The above is a minimal working example showing that the behaivour does not occur by default. You can click on Open in Overleaf just above the code block to see the output.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Loupiote3
Posts: 4
Joined: Tue Jul 31, 2018 2:47 pm

Issue when cross-referencing with short chapter names

Post by Loupiote3 »

Hi Johannes,

Many thanks for your reply and sorry for not posting a minimal working example straight away, I wasn't sure how to go about it. I tried running your code on my laptop and - no surprises there - it worked perfectly fine. Then I ran your example with my preamble and it worked too...
Then I compiled my document again and, there's the surprise, it worked as well. I didn't change anything in the preamble, and I don't remember having changed anything that could have affected this behaviour anywhere else either, so I will just be grateful it works and keep my surprise in check for today. I am wondering if this could be a matter of recompiling the references again and again - I did do a few cycles of F11 + compile before I posted the question, but...

Many thanks again for your help and all the best,

Lou
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Issue when cross-referencing with short chapter names

Post by Johannes_B »

Problem solved for now? Great.

Feel free to post more questions.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply