TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create an example environment with a counter which will be in sync with my subsections. So I'll have:

subsection 3.2
lemma 3.2
example 3.2
example 3.3
lemma 3.3

subsection 3.3
example 3.3
example 3.4

I find it hard to understand the \newcounter command and how it works. Plus, is there a command for \onsectionchange - so I can do (in pseudo code):

%example counter := subsection counter
share|improve this question
Be aware that even your minimal example has duplicate numbers for examples (example 3.3 in both subsection 3.2 and subsection 3.3). You have been warned. ;-) – DevSolar Nov 2 '11 at 12:06
You might want to check out my somewhat related question and its answers, which might shed some light on the use of \newcounter and some of the things you can to to counters. – DevSolar Nov 2 '11 at 12:10
up vote 3 down vote accepted

Use a theorem environment. Besides classical theorems, such numbered environments can be used for lemmas, definitions, examples, and more. So you don't have to take care of defining environments and counter adjustments.

A simple example:


There are various theorem packages which provides ways for customizing such numbered environments, see: Theorem packages: which to use, which conflict.

share|improve this answer
I tries this. The problem is that my Theorems are in italic and I want the Examples to be in plain text – Guy Nov 2 '11 at 11:48
No problem, just use any theorem package feature. Try: \usepackage{amsthm}\theoremstyle{definition} before your \newtheorem{example}{Example}[subsection]. And there are many ways for customizing font and structure. – Stefan Kottwitz Nov 2 '11 at 11:50

Your Answer


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.