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.

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.

share|improve this question

migrated from stackoverflow.com Apr 4 '11 at 15:49

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers

Look at the ntheorem, shadethm and thmtools packages, all of which let you define new environments in boxes with numbering.

share|improve this answer
add comment

Put it in an environment, like the listings package mentioned above, or you can define your own environment that will get its 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.

share|improve this answer
add comment

You could use the listings package. 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.

share|improve this answer
    
My examples are mostly mathematics, its notes taking for math class. Thanks a lot! –  FurtiveFelon Sep 25 '09 at 18:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.