tags:

views:

455

answers:

2

Working with LaTeX, I was just wondering how do you create a box around a set of related text such as an example in a textbook? I found \framebox or \makebox, but I can't figure out how to make it auto number such as Example 1.1 (for first example in chapter 1), or even manually add to it.

A: 

You could use the listings package. (http://www.tex.ac.uk/tex-archive/macros/latex/contrib/listings/listings.pdf)
I don't know how much it is suited for other than programming languages, but I think it is adaptable. Are your examples code listings? Anyway, here is an example:

\usepackage{listings}
...

\renewcommand{\lstlistlistingname}{Examples} % Label of Table of Listings
\renewcommand{\lstlistingname}{Example} % Label for every Listing
\renewcommand{\thelstlisting}{\thesection.\arabic{lstlisting}}
\lstset{frame=single,captionpos=b,basicstyle={\rmfamily}}

\begin{lstlisting}[caption={[short D.]long Description},language=ruby]
  array.each do |a|
    a.times { puts "Examples" }
  end
\end{lstlisting}

Edit:
For math there is an option mathescape=true, so formulas work inside single dollar signs.

andre-r
My examples are mostly mathematics, its notes taking for math class. Thanks a lot!
FurtiveFelon
A: 

Put it in an environment, like the listings package mentioned above, or you can define your own environment that will get it's own counter:

 \newenvironment{nam}[args]{begdef}{enddef}

\renewenvironment{nam}[args]{begdef}{enddef}

These commands define or redefine an environment.

nam -- The name of the environment. For \newenvironment there must be no currently defined environment by that name, and the command \nam must be undefined. For \renewenvironment the environment must already be defined.

args -- An integer from 1 to 9 denoting the number of arguments of the newly-defined environment. The default is no arguments.

begdef -- The text substituted for every occurrence of \begin{nam}; a parameter of the form #n in cmd is replaced by the text of the nth argument when this substitution takes place.

enddef -- The text substituted for every occurrence of \end{nam}. It may not contain any argument parameters.

Mica