[Tex/LaTex] Numbering new environment with chapter/section

captionsfloatsnumbering

If I have a new environment defined (with, say, trivfloat), is it possible to get that section to number with chapter/section? I use \numberwithin for equations, figures, and tables.

For example, my equations and figures are numbered 1.1, 1.2, 1.3, 2.1, …
(or even 1.1.1, 1.1.2, …) But if I have a new float type (say, graph), \numberwithin won't work.

\trivfloat{graph}
\numberwithin{graph}{section} % Error...

Same happens if I use \DeclareCaptionType from the caption package.

Any thoughts on how to get this effect?

Best Answer

The trivfloat package seems to defer (much of) the definition of its new floats using \AtBeginDocument, so you also have to use \AtBeginDocument{\numberwithin{graph}{section}} to change the floats' numbering.

\documentclass{amsart}

\usepackage{trivfloat}

\trivfloat{graph}

\AtBeginDocument{\numberwithin{graph}{section}}

\begin{document}

\section{First}

\begin{graph}[h]
(Graph content)
\caption{A graph}
\end{graph}

\end{document}

enter image description here