1

When I label my figures, they are labelled Figure 1, Figure 2, ... How can I have the labelling match the section it comes from? That is, if Figure 2 is in section 3, it will be labelled Figure 3.1.

\documentclass{article}
\usepackage{floats}
\usepackage[demo]{graphicx}
\usepackage[caption = false}{subfig}
\begin{document}
\section{A}
\begin{figure}[H]
\includegraphics[width = 2in]{something}
\caption{figure}
\label{fig}
\end{figure}
\end{document}
1
  • 1
    See also this question which explains chngcntr as suggested by @egreg
    – Thruston
    Jun 19 '13 at 22:12
3

You could load the amsmath package and issue the commands

\numberwithin{figure}{section}
\numberwithin{table}{section}
\numberwithin{equation}{section}

to get figure, table, equation environments numbered separately within sections.


Addendum, motivated by a comment by @egreg: Instead of using the command \numberwithin of the amsmath package, you could load the chngcntr package and make use of its \counterwithin macro, as follows:

\counterwithin{figure}{section}
\counterwithin{table}{section}
\counterwithin{equation}{section}

And, should you be working with a document class that numbers figures, tables, and equations separately within each chapter, say, and should you want to have these items numbered in plain, consecutive manner, you could do so by using the macro \counterwithout, as follows:

\counterwithout{figure}{section}
\counterwithout{table}{section}
\counterwithout{equation}{section}
4
  • 1
    There is also the dedicated package chngcntr that has even more features than the simple \numberwithing.
    – egreg
    Jun 19 '13 at 22:10
  • Have at look at the answer to the question I linked above.
    – Thruston
    Jun 19 '13 at 22:15
  • So \counterwithin/out can be used anywhere in the document then not just the preamble?
    – dustin
    Jun 19 '13 at 23:29
  • @dustin - I've edited the stuff in the addendum to better explain what the \counterwithout macro is about. At any rate, I'd use the command \numberwithin and \counterwithin only in the preamble. If you use them somewhere in the middle of the document, you'd risk confusing your readers terrible by having two different numbering systems.
    – Mico
    Jun 20 '13 at 1:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.