Text FormattingNumbering theorems and definitions within subsection

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
cyanapple
Posts: 3
Joined: Wed Apr 07, 2010 2:25 pm

Numbering theorems and definitions within subsection

Post by cyanapple »

This is small fragment of my .tex file:
\newtheorem{definition}{Definition}[subsection]
\newtheorem{example}{Example}[subsection]
\newtheorem{theorem}{Theorem}[subsection]

I have subsection, which number is for example 1.2 and within some theorems definitions and examples. The document looks like
definition 1.2.1
definition 1.2.2
definition 1.2.3
exapmle 1.2.1 //should be 1.2.4
example 1.2.2 //should be 1.2.5
theorem 1.2.1 //shoul be 1.2.6
Since I'm newbie to LaTeX, what is the best solution for this problem?

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Numbering theorems and definitions within subsection

Post by frabjous »

It's better to use a fully compiliable example, so we can see what packages and document class you're using, but assuming you're using amsthm or similar, you can use the other optional argument to \newtheorem to tell it to use the counter of one already defined, in your case:

\newtheorem{definition}{Definition}[subsection]
\newtheorem{example}[definition]{Example}[subsection]
\newtheorem{theorem}[definition]{Theorem}[subsection]

See the amsthm documentation for more info. If you're not using amsthm, tell us what you are using.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Numbering theorems and definitions within subsection

Post by gmedina »

Hi,

try

Code: Select all

\newtheorem{definition}{Definition}[subsection]
\newtheorem{example}[definition]{Example}
\newtheorem{theorem}[definition]{Theorem}
frabjous wrote: \newtheorem{definition}{Definition}[subsection]
\newtheorem{example}[definition]{Example}[subsection]
\newtheorem{theorem}[definition]{Theorem}[subsection]
This will produce compilation errors (you cannot use both optional arguments simultaneously).
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: Numbering theorems and definitions within subsection

Post by frabjous »

That's what I get for not testing, thanks.
cyanapple
Posts: 3
Joined: Wed Apr 07, 2010 2:25 pm

Re: Numbering theorems and definitions within subsection

Post by cyanapple »

Hi, thanks you all for help, it worked. I'm using amsmath.
Beer for everyone ;]
Post Reply