How Can I Number Subfigures within Sections in Latex?

  • Context: LaTeX 
  • Thread starter Thread starter ryan88
  • Start date Start date
  • Tags Tags
    Latex
Click For Summary
SUMMARY

To number subfigures within sections in LaTeX, use the command \numberwithin{figure}{section} in the document preamble. However, referencing subfigures may not yield the desired format, such as "Figure 4.2(a)" instead of "Figure 2(a)". A workaround involves using section labels in references, like Figure \ref{sec:comparison}.\ref{fig:fx}. Alternatively, adjusting the subfigure counter with \numberwithin{subfigure}{section} or creating a new counter for subfigures can also be effective, though the latter requires careful syntax.

PREREQUISITES
  • Familiarity with LaTeX document structure
  • Understanding of figure and subfigure environments in LaTeX
  • Knowledge of LaTeX referencing commands
  • Basic experience with LaTeX counters and commands
NEXT STEPS
  • Research the \numberwithin{subfigure}{section} command for subfigure numbering
  • Explore the use of \newcounter for custom subfigure counters
  • Learn about the \label and \ref commands for effective referencing
  • Investigate LaTeX packages like subcaption for enhanced figure management
USEFUL FOR

LaTeX users, technical writers, researchers, and anyone needing to format figures and subfigures in academic documents.

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
7K
  • · Replies 1 ·
Replies
1
Views
4K
  • · 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
5K