Change a reference number by editing the label name in your LaTeX source code

In LaTeX, a reference number is generated automatically when you create a label with the \label command and then call it with \ref or \eqref. The number itself — like "Figure 3" or "Equation 12" — comes from LaTeX's internal counter, not from something you type. To change what number appears, you either rename the label (which changes how you call it throughout the document) or you manually override the counter that generates the number.

The most common reason to do this is when you've deleted or reordered figures, equations, or sections and the numbering no longer matches your intent. LaTeX recompiles and renumbers everything automatically, but sometimes you want a specific object to have a specific number regardless of its position in the document.

Key Takeaways

  • Reference numbers in LaTeX are generated by counters tied to your document structure, not by the label name itself.
  • Renaming a label changes the reference throughout your document, but does not change the number LaTeX assigns to that object.
  • To force a specific number, use \setcounter to manually set the counter before creating the object.
  • Recompile your document after any change — LaTeX needs two passes to update all cross-references correctly.
  • The counter name depends on the object type: figure, equation, section, table, and so on.

Understanding how LaTeX assigns reference numbers

Every numbered object in LaTeX — figures, equations, sections, tables — has an associated counter. When you write \begin{figure}, LaTeX increments the figure counter by one. When you write \caption{My Figure} and \label{fig:example}, the label stores the current value of that counter. Later, when you write \ref{fig:example}, LaTeX retrieves that stored number and prints it.

The label name itself is arbitrary. You could name it fig:example, fig:1, or my_picture — the label is only a pointer. What matters is which counter value it points to. If you rename a label from fig:old to fig:new, you must also update every \ref{fig:old} in your document to \ref{fig:new}, but the number that prints stays the same.

Renaming a label to change how you reference it

If you want to change which label you use to call a reference, find the \label command inside the object and change the name. For example, if you have:

\begin{figure} \includegraphics{myimage.png} \caption{A sample image} \label{fig:old_name} \end{figure}

Change fig:old_name to fig:new_name. Then search your entire document for every instance of \ref{fig:old_name} and replace it with \ref{fig:new_name}. The number that appears when you compile will not change — only the label you use to reference it changes.

Most LaTeX editors have a find-and-replace function. In Overleaf, use Ctrl+H (or Cmd+H on Mac). In TeXShop or other desktop editors, the shortcut is usually the same. Replace all instances at once to avoid missing any.

Manually setting a counter to force a specific number

To make a figure, equation, or section display a number you choose, use the \setcounter command before creating the object. The syntax is:

\setcounter{counter_name}{number_minus_one}

Set the counter to one less than the number you want, because LaTeX increments the counter when it encounters the object. For example, to make the next figure display as "Figure 5":

\setcounter{figure}{4} \begin{figure} \includegraphics{myimage.png} \caption{This will be Figure 5} \label{fig:five} \end{figure}

The counter names are figure, equation, section, subsection, table, page, and so on. Use the singular form without backslash. If you are working with equations inside an align* environment, the counter is equation. For numbered lists, it is enumi (first level), enumii (second level), and so on.

Resetting numbering after deletions or reordering

When you delete a figure or equation from the middle of your document, LaTeX automatically renumbers everything that comes after it. If you had Figure 1, Figure 2, Figure 3, and you delete Figure 2, the next compile will show Figure 1, Figure 2 (the old Figure 3). All your references update automatically.

If this automatic renumbering is not what you want — for instance, if you are publishing a revised version of a paper and want to keep the original figure numbers — use \setcounter to lock in the numbers you need. Place it just before each object that should have a non-sequential number.

After you make changes, compile your document twice. The first pass generates the labels and counters. The second pass resolves all the cross-references. If you see question marks or broken references after one compile, that is normal — recompile and they will resolve.

Changing numbering style for a specific object type

If you want figures to be numbered by chapter (Figure 1.1, Figure 1.2, Figure 2.1) instead of sequentially, or equations to include the section number, use \numberwithin. This changes how the counter increments, not the label itself.

\numberwithin{figure}{chapter}

Place this in your preamble (before \begin{document}) to apply it to the entire document. When you move to a new chapter, the figure counter resets. The label names do not change, but the numbers they point to will now include the chapter number.

You can also use \renewcommand to change how a number is displayed. For example, to show equation numbers in parentheses:

\renewcommand{\theequation}{(\arabic{equation})}

This affects only the display format, not the underlying counter value. All your \ref commands still work the same way.

Frequently Asked Questions

Why do my references show question marks after I change a label?

You have renamed the label but not updated the \ref commands that call it. Search your document for the old label name and replace it with the new one. Then recompile twice.

Can I have two objects with the same number?

Yes. Use \setcounter to set both to the same value. However, this can confuse readers. A clearer approach is to use \label on the first object, then use \ref to point to it from the second object, so they always display the same number automatically.

What happens if I set a counter to a negative number?

LaTeX will display negative numbers. This is rarely useful. If you want numbering to start at zero or one instead of the default, set the counter in your preamble before \begin{document}.

How do I restart numbering for each chapter?

Use \counterwithin{figure}{chapter} in your preamble. This resets the figure counter to zero each time a new chapter begins. The same works for equations, tables, and other counters.

Do I need to recompile after every counter change?

Yes. Compile once to generate the new numbers, then compile again to update all cross-references. Some editors do this automatically; others require you to press the compile button twice.