2

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):

\onsubsectionchange{
%example counter := subsection counter
}
2
  • 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, 2011 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, 2011 at 12:10

1 Answer 1

5

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:

\documentclass{article}
\newtheorem{example}{Example}[subsection]
\begin{document}
\section{One}
\subsection{One}
\begin{example}
Text
\end{example}
\end{document}

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

2
  • 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, 2011 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, 2011 at 11:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .