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 sometimes want to give examples in a document I am writing. Because these examples are quite general it could be difficult for readers to see the difference between the examples and the theoretical analysis. Therefore I want to put a long vertical bar (that spans the entire example) in the margin indicating the text next to it is an example. It could be that the example uses two pages or more.

Is there any helpful package to do this. An environment would be fine. Something like this:


Other suggestions to indicate the difference are welcome too. First I thought using a different background color. But I want to keep the document printable in Black/White and reading text with a gray background isn't that easy. A horizontal line at the begin and end is also an option but after two pages people could get confused.

share|improve this question
up vote 17 down vote accepted

The framed package provides a leftbar environment that does something like what you want:

This is a test.
share|improve this answer
Could you edit this answer to include a little explanation. Ideally, answers shouldn't just be a code snippet. All you need to do is say something like "The framed package provides a leftbar environment that does something like what you want" – Seamus Feb 8 '11 at 16:26

You can also use PDF annotations with the pdfcomment package


enter image description here

share|improve this answer
Will these work in all PDF readers and will the appear when the document is printed? – doncherry Jan 15 '12 at 13:31
@doncherry 1. They will work in every PDF reader, which fully implements the PDF spec ;-) No, that's not just Adobe Reader, although that might be the Linux perspective. 2. For printing you have to allow printing annotations in the Prefernces (AR) and in the print dialog. There's a section in the documentation of pdfcomment – Josef Jan 15 '12 at 13:44

Have a look at changebar package: http://www.ctan.org/tex-archive/help/Catalogue/entries/changebar.html

An example:

\usepackage{lipsum}% for random text only


share|improve this answer

Another possibility for indicating an example: If your document has anything to do with code, you might want to consider use of \verb and the verbatim environment. All it does is place the example in monospaced font, and it's wysiwyg. So you can also type up LaTeX examples as-is. I use the \verb command for short, in-line examples, and the verbatim environment for longer ones like this:


This is the explanation for the \verb#lambda# function:
>>> #this is a comment 
>>> sq = lambda x: x**2
>>> sq(2)
will return \verb#4#.


produces this:

enter image description here

Note you don't have to use ## to delimit the \verb command, you can use another pair, like !!.

share|improve this answer
Is this an answer to another question? I fail to see the relation to the OP. – Hendrik Vogt Feb 8 '11 at 18:12
@Hendrik: He also asked for other suggestions to indicate examples. If his examples are of code, that could be one way to do it, no? – aeroNotAuto Feb 8 '11 at 18:21
OK, so your main point is the different font. Maybe you should point that out in the beginning of your answer. – Hendrik Vogt Feb 8 '11 at 18:37
@Hendrik: Yep. I explained that at the bottom of my answer, I can move that to the top. – aeroNotAuto Feb 8 '11 at 19:10
I'd explain that your suggestion is to use a different font "to indicate the difference". After all, this is the part of the question you're addressing, and I honestly didn't get it. – Hendrik Vogt Feb 8 '11 at 19:13

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.