Graphics, Figures & TablesFigure references all have same number

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
adamant
Posts: 3
Joined: Thu Jul 19, 2018 8:25 pm

Figure references all have same number

Post by adamant »

I have a paper of about 35 pages. It has about 8 figures, which while writing, I embed in the text. For submission the journal wants me to put the figures on separate pages at the end of the text.
When the figures are embedded in the text, the numbering and referencing is correct. When I simply move the lines embedding the figures (see below) to the end of the text, the figures are numbered correctly in the captions under the figures, but all references in the text are to Figure 5. I can see this in the .aux file.

Here is as sample of the lines to insert the figures. [removing \singlespacing makes no difference]

\begin{figure}[p!]
\centering
\includegraphics[width=0.5\textwidth]{ModalValues.pdf}
\singlespacing{ \caption{Modal values of the limit distribution.}
\label{fig:mode}
\end{figure}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

adamant
Posts: 3
Joined: Thu Jul 19, 2018 8:25 pm

Figure references all have same number

Post by adamant »

After several hours of trial and error, I discovered that when the figures are in a separate file (input at the end of the document) or just moved to the end of the document, the \singlespacing to control the layout of the \caption matters.
Removing that got the referencing right. Though at the expense of having double spaced captions.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Figure references all have same number

Post by Stefan Kottwitz »

Hi Adamant,

welcome to the forum!

The command \singlespacing is a simple switch. It switches to single spacing. It is not a command that takes an argument. By using the curly braces, the \caption command got its own local scope, grouped in braces. So it did not step up the figure counter, since the caption command effect stays local within the braces.

This would be different:

Code: Select all

Code, edit and compile here:
\begin{figure}[p!]
\centering
\includegraphics[width=0.5\textwidth]{ModalValues.pdf}
\singlespacing
\caption{Modal values of the limit distribution.
\label{fig:mode}
\end{figure}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Stefan
LaTeX.org admin
adamant
Posts: 3
Joined: Thu Jul 19, 2018 8:25 pm

Figure references all have same number

Post by adamant »

Thanks for that.
The odd thing is that when the figures were embedded in the text, rather than all put together at the end, that syntax (error) for \singlespacing{\caption{...}} didn't matter---caption still stepped up the counter. Only when the figures were bunched at the end did it matter.
But thanks---that was the problem.
kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Figure references all have same number

Post by kaiserkarl13 »

Sorry to reply to a "solved" post, but you might check out the endfloat package, which would satisfy your journal's request without you having to do essentially anything at all with the figures. (Now that you have solved the singlespace scoping problem.)
Post Reply