LaTeX How Can I Number Subfigures within Sections in Latex?

  • Thread starter Thread starter ryan88
  • Start date Start date
  • Tags Tags
    Latex
Click For Summary
The discussion revolves around numbering figures and subfigures in a LaTeX document, specifically the challenge of achieving the desired format for subfigures when using the command \numberwithin{figure}{section}. While the main figures are numbered correctly (e.g., "Figure 4.2"), subfigures are not following the same numbering scheme, resulting in outputs like "Figure 2(a)" instead of "Figure 4.2(a)". A workaround was suggested by referencing the section label alongside the subfigure label. Participants are exploring the use of the \numberwithin{subfigure}{section} command to address this issue, but there is uncertainty about its effectiveness and the correct syntax for implementing it. The conversation highlights the complexity of managing figure and subfigure numbering in LaTeX documents and the need for clear guidance on the appropriate commands.
ryan88
Messages
41
Reaction score
0
Hi,

In my report, I want figures to be numbered within sections, so I put the following in the preamble of my document:
Code:
\numberwithin{figure}{section}
This works great, except for when I am referencing subfigures. I have the following code:
Code:
\begin{figure}[h]
	\centering
	\subfigure[$f(x)$]{
		\includegraphics[width=0.4\textwidth]{figures/fx}
		\label{fig:fx}
	}
	\subfigure[$\Phi_{50}(x,y)$]{
		\includegraphics[width=0.4\textwidth]{figures/phi_comp}
		\label{fig:phi_comp}
	}
	\caption{$\Phi_{N}(x,y)$ for $N=1,20,50$}
	\label{fig:fx_phi_comp}
\end{figure}
Figure \ref{fig:fx} shows that ...

This produces something like "Figure 2(a) shows that ..." instead of "Figure 4.2(a) shows that ...". I have worked around this by doing the following:
Code:
Figure \ref{sec:comparison}.\ref{fig:fx} shows that ...
Where sec:comparison is the label I have applied to the appropriate section.

Is this the only way around this? Or am I doing something wrong?

Thanks,

Ryan
 
Physics news on Phys.org
What does altering the subfigure counter do? Something like

Code:
\numberwithin{subfigure}{section}
I've never used that numberwithin command, instead I would have defined the figure counter afresh with a \newcounter declaration for subfigures (please don't ask me to work out what it should be on the fly - I googled it and found at least 3 different suggestions for syntax, none of which I can verify as working).
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 9 ·
Replies
9
Views
6K
  • · Replies 1 ·
Replies
1
Views
4K