Text FormattingNumbering theorem within chapter

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Hanneke
Posts: 8
Joined: Sun Feb 07, 2010 9:36 pm

Numbering theorem within chapter

Post by Hanneke »

I was not sure where to start this topic. I hope I chose the correct forum.

My question:
I've got this to number the excercises \newtheorem{opgave}{Opgave}. Now I would likte to have it not normally numbered like 1, 2 or 3, but 1.1, 1.2, 1.3 etc. I tried with \setcounter{opgave}{3.4}, but that didn't work.

Is there any (easy) way to do this?

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
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Numbering theorem within chapter

Post by gmedina »

Hi,

you forgot to give some vital information: the document class that you are using. Assuming that you are using book or report and that you want to have your theorem environment numbered subordinately within chapters, use

Code: Select all

\newtheorem{opgave}{Opgave}[chapter]
If this doesn't solve your problem, please give us all the relevant information.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Hanneke
Posts: 8
Joined: Sun Feb 07, 2010 9:36 pm

Re: Setcounter

Post by Hanneke »

Looks like I can't define this environment that way.
! LaTeX Error: No counter 'chapter' defined.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.9 \newtheorem{opgave}{Opgave}[chapter]


My documentclass is article (\documentclass[a4paper,12pt]{article}).
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Numbering theorem within chapter

Post by gmedina »

Then use

Code: Select all

\newtheorem{opgave}{Opgave}[section]
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Hanneke
Posts: 8
Joined: Sun Feb 07, 2010 9:36 pm

Re: Setcounter

Post by Hanneke »

It works.
Last thing; how do I use setcounter with this? Again, I used \setcounter{opgave}{3.4}, now at the top of my document is .4 and the counting starts with 0.4. How to fix this?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Numbering theorem within chapter

Post by localghost »

Hanneke wrote:I was not sure where to start this topic. I hope I chose the correct forum. [...]
Just for notification. That's why we have a forum guide [1]. Read it and you will know were to place requests. By the way you can read all the annoncements you can find in the User Control Panel.

[1] View topic: Forum Guide (Read before posting!)


Best regards and welcome to the board
Thorsten¹
Hanneke
Posts: 8
Joined: Sun Feb 07, 2010 9:36 pm

Re: Setcounter

Post by Hanneke »

Doesn't say much more than the indexpage. ;) But 'enumerate' in the description could've lead me to this forum. Thanks anyway!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Numbering theorem within chapter

Post by localghost »

Hanneke wrote:[...] Last thing; how do I use setcounter with this? Again, I used \setcounter{opgave}{3.4}, now at the top of my document is .4 and the counting starts with 0.4. How to fix this?
Code transports information much better than words. So, build a minimal working example (MWE) to show the problem.
Hanneke
Posts: 8
Joined: Sun Feb 07, 2010 9:36 pm

Numbering theorem within chapter

Post by Hanneke »

Not sure if this is what you mean by an MWE, but however;

This code:

Code: Select all

\documentclass[a4paper,12pt]{article} 
\usepackage{amsmath, amsfonts, amssymb, amsthm, amsrefs}
\usepackage[dutch]{babel}
 \usepackage{graphicx}
\pagestyle{plain}
\usepackage{enumerate}
%\usepackage{a4wide}   
\theoremstyle{plain}                            
\newtheorem{opgave}{Opgave}[section]
\newtheorem{stelling}{Stelling}  
\theoremstyle{remark}                                       

\begin{document}
\setcounter{opgave}{3.4}
\begin{opgave}
Show that  $|b| \leq a$ if and only if $ -a \leq b \leq a$. 
\end{opgave}

\end{document}
Gives me: http://i165.photobucket.com/albums/u55/ ... exding.png
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Numbering theorem within chapter

Post by gmedina »

It's not clear to me what's your intent. If you want the first occurrence of the opgave environment to be numbered as 3.4, you will have to change two counters (after all each of those environments will be numbered using two counters: the one for sections and then the one corresponding to each theorem). Try something like

Code: Select all

\documentclass[a4paper,12pt]{article} 
\usepackage{amsmath, amsfonts, amssymb, amsthm, amsrefs}
\usepackage[dutch]{babel}

\theoremstyle{plain}                            
\newtheorem{opgave}{Opgave}[section]

\begin{document}

\setcounter{section}{3}
\setcounter{opgave}{3}
\begin{opgave}
Show that  $|b| \leq a$ if and only if $ -a \leq b \leq a$. 
\end{opgave}

\end{document}
I deleted parts of the codethat were not relevant for the example code (don't forget to include them again in your actual code). By the way, a4wide is an obsolete package and shouldnt be used anymore (refer to the l2tabu document); I also would suggest you to use enumitem instead of enumerate.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply