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

When you use \ref{} or \label{} commands in LaTeX, the reference number appears automatically based on the order things appear in your document. To change what number shows up, you edit the label name itself — not the number that displays. LaTeX recalculates all references when you compile, so changing one label updates every place that references it.

The most common reason to do this is reorganizing your document. If you move a figure, section, or equation earlier or later, its number changes automatically. If you want it to keep a specific number instead, you can force that number using the \setcounter command before the item appears.

This guide covers the three ways to control reference numbers: renaming labels, forcing specific numbers, and fixing broken references when you reorganize.

Key Takeaways

  • Reference numbers in LaTeX are automatic — they come from the order items appear, not from what you type in the label name.
  • To change which number displays, use \setcounter{section}{5} (or figure, equation, table) before the item you want to renumber.
  • Renaming a label from \label{fig:old} to \label{fig:new} does not change the number that displays — it only changes what you type in \ref{} commands.
  • After you reorganize sections or figures, compile your document twice so LaTeX updates all cross-references correctly.
  • If a reference shows a question mark instead of a number, the label name in \ref{} does not match any \label{} in your document.

Understanding how LaTeX assigns reference numbers

LaTeX does not read the label name to decide what number to show. Instead, it counts how many sections, figures, equations, or tables have appeared before that point in the document. The label name is just an internal tag so you can refer back to it later.

For example, if your document has three sections and you write \label{sec:introduction} in the first section, that label will always point to the number 1. If you later write \label{sec:methods} in the second section, it points to 2. The words "introduction" and "methods" in the label names do not affect the numbers at all.

This automatic numbering is why LaTeX is useful for long documents — if you add a new section at the beginning, every section number after it shifts down by one, and every \ref{} command that points to those sections updates automatically.

Renaming a label without changing its number

If you want to change a label name for clarity or consistency, edit the text inside \label{}. For example, change \label{fig:diagram1} to \label{fig:system_architecture}. Then update every \ref{fig:diagram1} in your document to \ref{fig:system_architecture}.

The number that displays stays the same because it depends on position, not the label name. If that figure was the third figure in your document, it will still be labeled as Figure 3 after you rename it.

Most LaTeX editors have a find-and-replace feature that makes this easier. In Overleaf, use Ctrl+H (or Cmd+H on Mac). In TeXShop or other desktop editors, the same shortcut usually works. Search for the old label name and replace it everywhere at once, then compile to verify the change worked.

Forcing a specific number with setcounter

If you want a section, figure, equation, or table to display a number other than what its position would normally give it, use \setcounter before it appears. The command looks like this:

\setcounter{figure}{5} tells LaTeX that the next figure should be number 6 (because counters start at 0). \setcounter{section}{2} makes the next section number 3. You place this command right before the item you want to renumber, usually on the line before \section{} or \begin{figure}.

This is useful when you have an appendix that should restart numbering, or when you are combining multiple LaTeX documents and want to control where numbering continues. For example, if your main document ends at Section 5 and you are inserting a separate file that starts with Section 1, you could add \setcounter{section}{5} before the included file so it continues at Section 6.

Fixing references that show question marks

When you see a question mark instead of a number — like "See Figure ?" — it means LaTeX cannot find a matching label. This usually happens because the label name in your \ref{} command does not exactly match the \label{} somewhere in your document.

Check three things: spelling (LaTeX is case-sensitive, so \ref{Fig:one} does not match \label{fig:one}), punctuation (underscores, hyphens, and colons must match exactly), and whether the label actually exists in your document. Search your source code for the label name to confirm it is there.

After you fix the mismatch, compile your document twice. The first compile finds the label; the second updates all references to it. If you compile only once, the reference may still show a question mark.

Reorganizing sections and updating references

When you move sections, figures, or equations around, their numbers change automatically — you do not need to edit anything. Just compile your document and LaTeX recalculates all positions.

However, if you move an item to a different file or delete it entirely, any \ref{} command that points to it will show a question mark. Search your document for the old label name and either delete the reference or point it to a different label that still exists.

If you are working in Overleaf or another online editor, the compile happens in the background, so you see updated numbers almost when ready. In desktop editors like TeXShop or MiKTeX, you may need to click Compile or Typeset manually.

Using custom numbering for special cases

Sometimes you want a figure or equation to have a letter instead of a number, or to use a different numbering scheme in an appendix. You can do this by redefining how LaTeX displays the counter.

For example, \renewcommand{\thefigure}{A\arabic{figure}} makes figures display as A1, A2, A3 instead of 1, 2, 3. Place this command in your preamble (before \begin{document}) to explore it to the whole document, or place it in a specific section to explore it only there.

This is more advanced than straightforward renumbering, but it is useful when you have appendices that need different numbering or when you are following a style guide that requires custom numbering schemes.

Frequently Asked Questions

Why does my reference show a question mark even though I have the label?

The label name in your \ref{} command does not match the \label{} exactly. Check for spelling differences, capitalization (LaTeX is case-sensitive), and punctuation. After you fix it, compile twice — the first compile finds the label, the second updates the reference.

Can I make a figure stay as Figure 3 even if I move it to a different position?

Yes, use \setcounter{figure}{2} right before the figure environment. This forces the next figure to be number 3. However, this can confuse readers if figures are out of order, so use it only when you have a specific reason.

What happens if I rename a label but forget to update the \ref commands?

The \ref{} commands that still use the old label name will display question marks. Use find-and-replace to change all instances of the old label name to the new one, then compile twice.

Do I need to compile twice after changing a reference?

Yes. The first compile reads all labels and stores them. The second compile uses that information to fill in the reference numbers. If you compile only once, references may still show question marks or old numbers.

Can I have different numbering styles in different parts of my document?

Yes, you can use \renewcommand{\thefigure} or similar commands to change how numbers display. Place the command before the section where you want the new style to start, and use another \renewcommand to switch back if needed.