Text FormattingSetting <section> as the parent counter of <figure>

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
EagleLee
Posts: 4
Joined: Fri Nov 11, 2022 3:49 pm

Setting <section> as the parent counter of <figure>

Post by EagleLee »

Hello all

Using the original class {article}, I insert several pictures into some sections and the captions of figures are counted as Figure 1, Figure 2... normally.

I wanna get such formats as "Figure 1.1" or "Figure 1.2" in Section 1, "Figure 2.1" or "Figure 2.2" in Section 2 and so on. I use \setcounter{figure}{0} after every \section{}.

Though the ideal results are outputted, I think there must be a simpler way. I guess the counter <section> can be set as the parent counter of <figure> before \begin{document}, in which the figures inside Section X can be counted as "Figure X.1" or "Figure X.2" automatically. However, I've searched the keywords online and "texdoc-"ed the packages {hyperref} and {caption} in cmd and have little clues. Is the simpler way feasible?

I would be deeply grateful to anyone who can solve it!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Setting <section> as the parent counter of <figure>

Post by Bartman »

Read the description of the \counterwithin command in section "Counters and Lengths" of "File t ltcounts.dtx" in source2e.
EagleLee
Posts: 4
Joined: Fri Nov 11, 2022 3:49 pm

Setting <section> as the parent counter of <figure>

Post by EagleLee »

Bartman wrote:Read the description of the \counterwithin command in section "Counters and Lengths" of "File t ltcounts.dtx" in source2e.
source2e is really a charming document and it works perfectly! Thanks for your enlightening answer!
Post Reply