How Can I Number Subfigures within Sections in Latex?

  • LaTeX
  • Thread starter ryan88
  • Start date
  • Tags
    Latex
In summary, the conversation is about a report where the figures need to be numbered within sections. The person is having trouble with referencing subfigures and has found a workaround by labeling the appropriate section. They are also discussing different ways to use the numberwithin command.
  • #1
ryan88
42
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
  • #2
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).
 
  • #3



Hello Ryan,

It seems like you are on the right track with your workaround. The \numberwithin{figure}{section} command will number your figures within each section, but it does not affect the numbering of subfigures. In order to have the subfigures also be numbered within the sections, you can use the subcaption package and add the following line to your preamble:
\usepackage{subcaption}

This will allow you to use the command \numberwithin{subfigure}{section} to number your subfigures within each section. So your preamble should now look like this:
\numberwithin{figure}{section}
\usepackage{subcaption}
\numberwithin{subfigure}{section}

This should give you the desired result of "Figure 4.2(a) shows that ..." when referencing your subfigures. Let me know if you have any further questions or if this does not work for you.

Best regards,
 

FAQ: How Can I Number Subfigures within Sections in Latex?

1. What is "Latex numbering of subfigures"?

Latex numbering of subfigures is a feature in the Latex typesetting system that allows users to label and automatically number subfigures within a figure. This is particularly useful for scientific or technical documents with multiple figures containing subfigures.

2. How do I use Latex numbering of subfigures?

To use Latex numbering of subfigures, you need to first load the "subcaption" package in your Latex document. Then, you can use the "subfigure" environment to create subfigures within a figure. You can then use the "label" command to assign a label to each subfigure and the "ref" command to refer to the subfigure in the text.

3. Can I customize the numbering format for subfigures in Latex?

Yes, you can customize the numbering format for subfigures in Latex by using the "subcaption" package options. For example, you can change the numbering style from numbers (1, 2, 3) to letters (a, b, c) or Roman numerals (i, ii, iii) by using the "style" option.

4. Are there any limitations to using Latex numbering of subfigures?

One limitation of using Latex numbering of subfigures is that it cannot be used with the "figure*" environment, which allows figures to span across multiple columns. Additionally, the "subfigure" environment cannot be nested within another "subfigure" environment.

5. Can I use Latex numbering of subfigures in non-technical documents?

Yes, Latex numbering of subfigures can be used in any Latex document, not just scientific or technical ones. It can be useful for creating organized and labeled figures, even in non-technical documents such as reports or presentations.

Similar threads

Replies
5
Views
3K
Replies
2
Views
5K
Replies
5
Views
4K
Replies
7
Views
3K
Replies
1
Views
3K
Replies
2
Views
2K
Back
Top