0

I have application with which I am generating my PDF from various chapters and sections, by adding and removing chapter and sections. So I found problem with example numbers and image numbers. For example I am writing in chapter 2 that Something is shown on example image (2.1) and there is image 2.1. But if I remove chapter 1, my chapter 2, becomes chapter 1 and my image number is 1.1, not 2.1 . How can I set my example numbers correct?

Thanks.

Sean Allred
  • 27,421
Mantas
  • 265
  • That is what \label and \ref is for. – John Kormylo Nov 25 '15 at 14:54
  • Yes I am using \label to set image number, so how to set in text a number of that image? If you can make me an example. Lets say I want to say: Something is shown in image (image number) – Mantas Nov 25 '15 at 15:02
  • what if I use my example few times and after another examples? I use \label{fig:image15} maybe I should rename it somehow every label in different name? – Mantas Nov 25 '15 at 15:15
  • The linked answer provides the objective, which is similar to what you're looking for. Place \label{<whatever>} within your environment - after \caption if inside a figure or table - and \ref{<whatever>} within your document body. – Werner Nov 25 '15 at 15:17
  • but if my \label is always same :) what then? but numbering works perfectly – Mantas Nov 25 '15 at 15:17
  • @Mantas: It is good practice to use descriptive names for \labels, especially since they may change. For example, \label{fig:trees} is more descriptive than \label{fig:image15}. You have to choose a unique \label for each object. That's the law. – Werner Nov 25 '15 at 15:18
  • so you offer to change every \label{fig:name}name? – Mantas Nov 25 '15 at 15:19

1 Answers1

0

\label{name} stores \thefigure together with "name" in the aux file. More accurately, it stores the counter last incremented by \refstepcounter. \ref{name} retrieves this stored text, but it takes a second run to show changes.

\documentclass{book}
\usepackage{mwe}

\begin{document}
\chapter{Start}
See Figure \ref{name}.

\begin{figure}[h]
\includegraphics{example-image}
\caption{test}\label{name}% must come after \caption
\end{figure}

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120