Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
\DeclareCaptionType resp. \DeclareFloatingEnvironment has an optional parameter within=section, so there is no need for \numberwithin here. –  Axel Sommerfeldt May 17 '12 at 5:00
add comment

1 Answer

up vote 4 down vote accepted

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

share|improve this answer
    
And cannot you simply put \numberwithin{graph}{section} just after \begin{document} ? –  tohecz May 16 '12 at 16:54
    
Awesome! That works wonderfully. And nice explanation. Thanks :) –  Ben P. May 16 '12 at 16:55
    
@tohecz I prefer preamble solutions because they may be used in a user's custom mypackages.sty or myclass.cls. –  lockstep May 16 '12 at 16:56
    
@tohecz Yes, I tried that and it works also. However, the AtBeginDocument is better for me as this is going in a .sty file. –  Ben P. May 16 '12 at 16:56
    
@tohecz: Like with many suggestions there are alternatives. In this case, separating content from setup (macro construction and package inclusion) is usually good practice. –  Werner May 16 '12 at 17:06
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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