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 need to use an example environment like the following.

\begin{example}[My Caption, mylabel]
My example text

It should show the text inside a verbatim environment, the caption (like a figure) Example 1: My Caption and the label mylabel to refer to the example.

Can anyone help me, please?

I tried with this, but it doesn't work with the verbatim environment.

  \vspace{0.3cm} {\bf{Example \thechapter.\arabic{example}} - #1} \\ \sf


share|improve this question
Thanks, I solved using the listings package. – auino Jul 20 '12 at 15:11

I've solved in this way.


And then using this sample:

\begin{example}[caption=My Caption,label=mylabel]
My example text
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.