LaTeX LaTeX: referencing figures within enumerate environment

  • Thread starter Thread starter arboretum
  • Start date Start date
  • Tags Tags
    Latex
AI Thread Summary
The discussion centers around an issue in LaTeX where a figure's label is incorrectly referencing the enumeration counter instead of the figure counter. The user describes their setup, noting that when they reference the figure in their text, it incorrectly shows "Figure 10" instead of the expected "Figure 1." They consider a workaround involving ending the enumerate environment to place the figure but find it cumbersome. A suggested solution is to place the label inside the caption argument of the figure, which ensures that the reference correctly points to the figure number rather than the enumeration number. This adjustment resolves the referencing issue effectively.
arboretum
Messages
2
Reaction score
0
I've not been able to find any sort of answer to this using google, but perhaps it's because the searches I've used have not been specific enough, so I apologize for bringing it up if this is answered on every LaTeX-oriented website. In any case, here's my setup:

Code:
\begin{enumerate}
\item (first item---blah blah blah)

\item (second item---blah blah blah)
...
...
...
\item (tenth item---blah blah blah)
% this is the first figure in the file
\begin{figure}[!h]
    \includegraphics{yourmomlookslikeacow.eps}
    \label{fig:momcow}
    \caption{Your mother resembles a bovine}
\end{figure}

\item (eleventh item---blah blah blah)

\item (twelfth item) As we can see in Figure~\ref{fig:momcow}, your 
mother looks like a cow.
\end{enumerate}

What will happen is that yourmomlookslikeacow.eps will be the first figure in the file and will have a caption that says "Figure 1: Your mother resembles a bovine" as it should, but when I reference the figure in item #12, it will say "As we can see in Figure 10, your mother looks like a cow." For some reason, the label seems to associate itself with the value of the enumi counter at item #10 instead of the figure counter at figure #1. Even if I wanted to have something like "See Figure 10.1" by using \numberwithin{figure}{enumi}, all that would happen is that my caption would be modified properly, but my reference would still say "Figure 10."

I think one way of fixing this would be to end the enumerate environment, place in the code for the figure, then restart the enumerate environment at the appropriate number, but that seems clunkier and less good-programmingly good than simply writing "Figure~1" in my code when I want Figure 1. I'd really appreciate your help, and I want to point out that I don't have any beef with your mother, I just don't feel like using foo and bar.
 
Physics news on Phys.org
Hi arboretum,

Put the label inside the caption argument:

Code:
\begin{enumerate}
\item (first item---blah blah blah)

\item (second item---blah blah blah)
...
...
...
\item (tenth item---blah blah blah)
% this is the first figure in the file
\begin{figure}[!h]
    \includegraphics{yourmomlookslikeacow.eps}   
    \caption{\label{fig:momcow} Your mother resembles a bovine}
\end{figure}

\item (eleventh item---blah blah blah)

\item (twelfth item) As we can see in Figure~\ref{fig:momcow}, your 
mother looks like a cow.
\end{enumerate}
 

Similar threads

Replies
5
Views
4K
Replies
5
Views
5K
Replies
2
Views
6K
Replies
1
Views
3K
Replies
1
Views
5K
Replies
4
Views
5K
Replies
6
Views
18K
Back
Top