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

\begin{example}
...
\end{example}

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

4 Answers

up vote 15 down vote accepted

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

\documentclass{article}
\usepackage{framed}
\begin{document}
\begin{leftbar}
This is a test.
\end{leftbar}
\end{document}
share|improve this answer
4  
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
add comment

You can also use PDF annotations with the pdfcomment package

\documentclass{scrartcl}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage[svgnames,rgb]{xcolor}
\usepackage[subject={Top1},author={Josef}]{pdfcomment}
\begin{document}
\begin{pdfsidelinecomment}[color=red,icolor=yellow,caption=inline,linebegin={/Butt},lineend={/Square},linewidth=2bp,linesep=1cm]{Example}
\lipsum[2]
\end{pdfsidelinecomment}
\end{document} 

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

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

An example:

\documentclass{article}
\usepackage[color]{changebar}
\cbcolor{blue}
\usepackage{lipsum}% for random text only
\begin{document}

\cbstart
\lipsum[1]
\cbend

\lipsum[2]
\end{document}
share|improve this answer
add comment

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:

\documentclass{article}
\begin{document}

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

\end{document}

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? –  asia1281 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. –  asia1281 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
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.