TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a document organized into several chapters. In each chapter, theorems are numbered by section (1.1, 1.2, ... even in chapter 5). I often would like to refer to theorems in different chapters. However, if I am in chapter 6 and refer to theorem 1.3 in chapter 1, it is rather ambiguous, and the reader might assume that "theorem 1.3" meant the current chapter. Is there an automatic way of configuring things so that the cross-referencing will say "theorem 1.3" only if it is really the current chapter, but "theorem I.1.3" (or something like that) if the cross-referencing spans chapters?

share|improve this question
How exactly do you define the theorems? Are you using e.g. the amsthm package? – Martin Scharrer Feb 6 '11 at 16:44
@Martin: Right now I'm using ntheorem with cleveref, though I'm happy to change this. – Akhil Mathew Feb 6 '11 at 16:46
I'd always write "Theorem 1.3" with capital "T". – Hendrik Vogt Feb 7 '11 at 9:11
up vote 14 down vote accepted

You can add a conditional in the reference number which checks if the chapter number of the referenced label is identical to the current chapter number and then suppress the chapter number in the output.

Here a way to do it. I used ntheorem and loaded cleveref because you said you are using it. It might need some minor adjustments to work in your document, but you get the idea.


% From your post I assume you have settings like this:

% Redefine the format of the theorem number:

% May print the chapter number
   % Tests if current chapter is equal to the chapter number of label)
     % Print nothing if so
     % Set 'chapter' locally (=> no \setcounter) to the label chapter and
     % print it in the usual format followed by a dot

% Test document:
Here \ref{theo:11}  % prints "1.1"
and there \ref{theo:21}. % print "II.1.1"



There \ref{theo:11}  % prints "I.1.1"
and here \ref{theo:21}. % print "1.1"


share|improve this answer
This is great. Thanks! – Akhil Mathew Feb 6 '11 at 20:35
Yes, very good idea. Well done, this is great ! – user4552 Mar 30 '11 at 18:57
@NicolasGreliche: Please only add solutions as answers. Please up-vote good answers instead or add comments. However, for both you need a certain amount of reputation points (15 for up-voting, 50 for commenting everywhere). This is a protection for spam-bots. I converted your post to a comment to keep the site tidy. – Martin Scharrer Mar 30 '11 at 19:03
Amazing trick, thanks a lot! – Olivier Jul 13 '11 at 12:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.