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.

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
}
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
add comment

1 Answer

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:

\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.

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
add 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.