# Reference incremented labels of figures automatically

Is there any way to make Figures-label with automatically incremented counter. I have this code:

\documentclass[10pt,a4paper,openany]{book}
\usepackage{graphicx}
\begin{document}

\begin{figure}
\includegraphics{natural-number-line-1.pdf}
\caption{image-Numbe-1}
\label{fig:f1.1}
\end{figure}
\ref{fig:f1.1}\\
%%%%%%%%%%%%%%%%
\begin{figure}
\includegraphics{natural-number-line-2.pdf}
\caption{image-Numbe-2}
\label{fig:f1.2}
\end{figure}
\ref{fig:f1.2}\\
%%%%%%%%%%%%%%%%
\begin{figure}
\includegraphics{natural-number-line-3.pdf}
\caption{image-Numbe-3}
\label{fig:f1.3}
\end{figure}
\ref{fig:f1.3}\\
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
\end{document}


when i insert a new image and reference it, so i must change all the labels after it, like that:

\documentclass[10pt,a4paper,openany]{book}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\includegraphics{newimage.pdf}
\caption{newimage}
\label{fig:f1.1}
\end{figure}
\ref{fig:f1.1}\\
%%%%%%%%%%%%%%%%
\begin{figure}
\includegraphics{natural-number-line-1.pdf}
\caption{image-Numbe-1}
\label{fig:f1.2}
\end{figure}
\ref{fig:f1.2}\\
%%%%%%%%%%%%%%%%
\begin{figure}
\includegraphics{natural-number-line-2.pdf}
\caption{image-Numbe-2}
\label{fig:f1.3}
\end{figure}
\ref{fig:f1.3}\\
%%%%%%%%%%%%%%%%
\begin{figure}
\includegraphics{natural-number-line-3.pdf}
\caption{image-Numbe-3}
\label{fig:f1.4}
\end{figure}
\ref{fig:f1.4}\\
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
\end{document}


I have more than 1000 figures, and my question is: Is there any way to make label with automatically incremented counter, so i can insert and reference figures in any place without change all the labels of figures after that?

• The argument of \label is just an arbitrary name. It has nothing to do with the figure number you are getting. Thus, use descriptive labels (such as fig:introductory_figureor fig:scope,...) rather than labels that include chapter/figure numbers. – leandriis Sep 30 '20 at 18:28
• The whole purpose of the \label, \ref mechanism is that figures, tables,... are automatically numbered and referenced correctly, even if you change their order. Therefore, don't use labels that just make sense if your images stay in a spcific order. Probably you could use the filename as the label? – leandriis Sep 30 '20 at 18:36
• Just make sure you have unique labels. The number you see in the PDF is completely unrelated to the text used in the labels. The figures are numbered in the order they appear in the document, if you add a new figure at the start, the numbering of the figures, and the cross-references, will update. – Torbjørn T. Sep 30 '20 at 18:47
• Probably take a look at this answer: tex.stackexchange.com/a/123511/134144 It shows a way to automatically use the file name as the label name as well. Hence no need to invent 1000 labels and no order confusion if you add images later on since the labels are not tied to the figure numbers. – leandriis Sep 30 '20 at 19:52
• the entire reason for having the \label mechanism is so that you do not need to adjust the numbering if you add or insert figures (or sections) it is normally considered bad style but if you want to use an incremental number to generate unique references that will work fine, but there is no relation between that internal numbered id used for \label and the actual printed figure number, so there is no need to change the labels or references when you re-order the figures. Auto-generating the label defeats the process as then you have no way to have a stable id to use with \ref. – David Carlisle Sep 30 '20 at 22:02