General\ref in headings

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
SomeTex
Posts: 5
Joined: Mon Apr 07, 2008 6:33 pm

\ref in headings

Post by SomeTex »

I have some section titles that use a "\ref". This works fine, but when I enable headings, the headings (from the default report style) include the section titles and thus the \refs. However, the headings can not resolve the \refs and I end up with question marks in the heading (even after multiple builds).

Any ideas?

Recommended reading 2024:

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

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

User avatar
Stefan Kottwitz
Site Admin
Posts: 10320
Joined: Mon Mar 10, 2008 9:44 pm

\ref in headings

Post by Stefan Kottwitz »

Hi,

when I use \ref inside a section title, then it's working fine inside the headings of a report document, the reference is resolved.
You could give us a minimal working example, that shows the problem, then we could provide specific help.

Stefan
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

\ref in headings

Post by gmedina »

I think I do not fully understand your problem. Can you please be a little more explicit? Better yet, can you please post a minimal working example clearly showing the undesired behaviour?
1,1,2,3,5,8,13,21,34,55,89,144,233,...
SomeTex
Posts: 5
Joined: Mon Apr 07, 2008 6:33 pm

\ref in headings

Post by SomeTex »

I've figured out that the problem only occurs when I include the hyperref package. Here's an example. (sorry about the length, the first heading only appears on the second page of a chaper)

Code: Select all


\documentclass[12pt,twosided]{report}

\usepackage{hyperref}
\usepackage{theorem}
\newtheorem{thm}{Theorem}

\begin{document}
\pagestyle{headings}

\chapter{Example Reference \ref{foo}}

\begin{thm}\label{foo}
Theorem....
\end{thm}

fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 

fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 
fill text fill text fill text fill text fill text fill text fill text fill text 

\end{document}
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

\ref in headings

Post by gmedina »

How about using the optional argument of the sectional commands, as the following example suggests?

Code: Select all

\documentclass{report}
\usepackage[english]{babel}
\usepackage{blindtext}

\begin{document}
\tableofcontents

\pagestyle{headings}

%the optional argument will be used in the Table of Contents and in the headings
\chapter[First chapter]{First chapter referencing section~\ref{sec:secone}}
\Blindtext

\Blindtext

\section{First section}
\label{sec:secone}

\end{document}


Remark
: the blindtext package was loaded only to automatically generate some text.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
SomeTex
Posts: 5
Joined: Mon Apr 07, 2008 6:33 pm

Re: \ref in headings

Post by SomeTex »

Well, that is certainly better than having question marks in my document. Thanks for the suggestion. I'll either do that or just not use the hyperrefs (I have many appendix sections labeled "Proof of Lemma \ref{}" so an alternate heading label won't really distinguish between the sections unless I explicitly use the numbers, which sort of defeats the whole point of \refs.)
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Re: \ref in headings

Post by gmedina »

Notice that the hyper-reference to the theorem, lemma, etc. will work in the actual title of the sectional unit. I do not think that it is usual for the page headings to contain hyperlinks though.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
Stefan Kottwitz
Site Admin
Posts: 10320
Joined: Mon Mar 10, 2008 9:44 pm

Re: \ref in headings

Post by Stefan Kottwitz »

Hi,

you may use uppercase labels like FOO, and it will work, because the headings use uppercase.
Test it or check the warnings in your logfile concerning undefined references, they are printed in uppercase.

If you had checked the log, you would have seen another warning, the option twosided is undefined, it must be twoside.

Stefan
SomeTex
Posts: 5
Joined: Mon Apr 07, 2008 6:33 pm

Re: \ref in headings

Post by SomeTex »

Nice catch Stefan, the problem was the conversion to uppercase.

@gmedina: Yeah, I don't really care if the heading has a hyperlink, I just want it to have the correct number for the ref.
Post Reply