6

Suppose in Chapter 3 I have Theorem 3.17. I need to get the "17", NOT the "3.17" which would readily be obtained using \label then \ref. How do i do that?

Edit: (Probably a more relaxing condition): I need that number "17" mostly inside or near (just below) the current theorem environment.

fajar
  • 357
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. If I remember correctly, you can find this feature in varioref package. I can't provide you more details since I don't really know that package. – yo' Feb 20 '14 at 14:29
  • I believe this has already asked before. Does http://tex.stackexchange.com/questions/10400/cross-referencing-in-multiple-chapters help? – egreg Feb 20 '14 at 16:01

2 Answers2

4

If you only want to know the current value of the theorem counter you can also use

\the\value{theorem}

If you want to add a number to this value, you can use the construct

\the\numexpr<calculation>\relax

For example, to add 1 to that value

\the\numexpr\the\value{theorem}+1\relax

Here's a MWE:

\documentclass{book}

\newtheorem{theorem}{Theorem}[chapter]

\begin{document}

\setcounter{chapter}{2}  % only for the example

\chapter{Test}

\setcounter{theorem}{16} % only for the example

\begin{theorem}
  This is my theorem
\end{theorem}

\noindent Here I want to know which is the number of the current theorem:
\the\value{theorem}

\noindent Here I want to know which is the number of the next theorem: 
\the\numexpr\the\value{theorem}+1\relax

\end{document} 

Output:

enter image description here

karlkoeller
  • 124,410
2

If you don't want to make a reference to a theorem, but just the number of the upcoming theorem, say

\number\value{theorem}

at the position you want to have it. (This solution assumes that theorem is the counter responsible for the theorem environment.)

Changing the output of \ref can be done with varioref package, as stated by user tohecz before.

If you want to advance the counter by one, there are three possibilties, which should not be applied simultaneously:

\stepcounter{theorem}

or

\refstepcounter{theorem}

or

\addtocounter{theorem}{1}

The last method can be applied if you want to add (or even subtract) another value -- just exchange the number '1' by a positive or negative integer.

  • This works! I never knew this. Now, how do I add a number to the produced number? Something like \number\value{theorem}\plusone – fajar Feb 20 '14 at 23:26
  • @fajar: I have added some text and pieces of code in my solution. –  Feb 21 '14 at 05:08