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.

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 was wondering if there is any formal environment for specifying 'examples' through out the text. If not, which environments do you recommend?

share|improve this question
What kind of examples? – N.N. Jun 21 '11 at 7:49
@N.N. A simple one which gives some indentation and enables a logical recognition of the example, through \label{example1} and \ref{example1}. – Md Oliya Jun 21 '11 at 8:00
up vote 31 down vote accepted

You could use the amsthm package. As per their recommendations, which is what most people use, you should define the environment as


and than use is as

This is the example.

Note however, that the above definition will give the examples its own counter. If you already have theorems and definitions using the thm-counter, you might want to consider using


since it can be very confusing for the reader if you have Theorem 3, Lemma 3, Definition 3 and Example 3 on different pages.

share|improve this answer
Thank you @Carsten. but loading amsthm errs with "Command \proof already defined." I am using Springer llncs.cls. Any advice? – Md Oliya Jun 21 '11 at 8:34
@Md Oliya In that case you do not need the amsthm package. llncs provides this feature itself. According to section 8 of its documentation you should simply use \begin{example} <text> \end{example}. For using the same counter for Theorems, Definitions etc load the class with the option envcountsame. – Carsten Thiel Jun 21 '11 at 8:44
Thanx @Carsten. the amsthm package works great. just a question: the counters are like section_number.counter (e.g III.1). how can i use a simple counter? i.e. no section numbers – Md Oliya Jun 24 '11 at 3:06
@Md Oliya use \newtheorem{exmp}{Example} without the [section] – Carsten Thiel Jun 24 '11 at 7:37
---------Great! – Md Oliya Jun 25 '11 at 6:40

You can make a simple example environment as follows:

  \textbf{Example \arabic{examplecounter}}%
  A simple example environment


Some text: \lipsum[4]

  Another example

Example~\ref{ex:another} comes after example~\ref{ex:simple}

So you have an environment which is basically just a wrapper for a quote environment which has its own counter. You can replace quote with something else that adds indentation more to your liking, but the basic idea is there.

If you want it to include the section number as part of the example (e.g. example 1.2) then that's a little more work and maybe something like amsthm or ntheorem is a better bet...

note that \refstepcounter increments the environment's counter, and also makes the environment "visible" to the referencing mechanism.

share|improve this answer

Here is an alternative using mdframed and xparse (xparse is not absolutely necessary, but I adopted it as my main syntax for defining commands and environments due to its flexibility)


\usepackage{mdframed} % Add easy frames to paragraphs
\usepackage{lipsum} % For dummy text
\usepackage{xparse} % Add support for \NewDocumentEnvironment
\definecolor{graylight}{cmyk}{.30,0,0,.67} % define color using xcolor syntax

\newmdenv[ % Define mdframe settings and store as leftrule

\NewDocumentEnvironment{example}{O{\textbf{Example:}}} % Define example environment




enter image description here

(fontspec used because I compile with XeLaTeX)

share|improve this answer

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.