# Examples enumerated in the margins

I am writing a paper about phonetics that contains lots of examples, usually organised in tables. What I would like is to have these examples enumerated in the margins. Specifically, I need an environment called example, so that whatever I write

\begin{example}
some examples
\end{example}


LaTeX prints this text along with a margin note saying, e.g., "Example 2.7". It is supposed to work a bit like in this book.

I did try with the following code:

\newenvironment{example}
{
\marginpar{\begin{center}Examples\\ \refstepcounter{examples}\theexamples\end{center}}
\medskip\begin{center}
}
{
\end{center}\medskip
}


but the numbers are not always aligned correctly with the examples in the margins.

Any good ideas about how to make this? :-)

UPDATE: On request from cmhughes, I now add my entire preamble so that he may see the problem. :-)

\documentclass[a4paper]{memoir}

%Memoir settings
\setlrmarginsandblock{*}{3.5cm}{0.75}
\setulmarginsandblock{3cm}{*}{1.2}
\checkandfixthelayout[nearest]

\usepackage{amsmath,amssymb,geometry,graphicx,amstext,enumerate,multirow,color,multicol,comment,xcolor}
\usepackage{cleveref}
\usepackage[ansinew]{inputenc}
\usepackage{wasysym}
\usepackage{tipa,vowel,textcomp}

\chapterstyle{veelo}

\usepackage[amsmath]{ntheorem}      % for theorem-like environments

% margin theorem
\makeatletter
\newtheoremstyle{mymargin}%
\makeatother

% my example
\theoremstyle{mymargin}
\theorembodyfont{}      % customize these to suit your tastes
\theoremsymbol{}
\theoremprework{}
\theorempostwork{}
\theoremseparator{}
\newtheorem{example}{example}
\numberwithin{example}{section}
%\usepackage{subcaption}

\begin{document}


However, using this preamble resulted in the example enumeration looking like this:

See, the number appears to the right of the margin.

Do you have an idea what the problem may be? :-)

-

There's a few ways that you can do this. Personally, I favour the ntheorem package

I have loaded the geometry package with showframe=true just to highlight the page boundary, and lipsum just for sample text.

\documentclass{report}

\usepackage[showframe=true]{geometry}
\usepackage{lipsum}                 % for sample text
\usepackage{amsmath}
\usepackage[amsmath]{ntheorem}      % for theorem-like environments

% margin theorem
\makeatletter
\newtheoremstyle{mymargin}%
\makeatother

% my example
\theoremstyle{mymargin}
\theorembodyfont{}      % customize these to suit your tastes
\theoremsymbol{}
\theoremprework{}
\theorempostwork{}
\theoremseparator{}
\newtheorem{myexample}{example}
\numberwithin{myexample}{section}

\begin{document}

\begin{myexample}
\lipsum[2]
\end{myexample}
\end{document}


You could achieve the same output by using a simple list, using the enumitem package, but I think a theorem package is most appropriate here.

-
Thanks for the answer :-). There are just two problems, which I'm sure you'll be able to solve. :-) First of all, the number is vertically aligned by the middle of the text within the environment rather than at the top. And second of all, if the text in the environment is centered, then the number appears to the right of the margin border. Is there an easy solution to this? :-) –  Gaussler Mar 5 '13 at 19:07
@Gaussler I'm afraid I don't understand- my code aligns example 0.0.1 at the top of the environment. I don't really understand the centering issue- you want the body of the text to be centered? –  cmhughes Mar 5 '13 at 22:34
Oh, sorry the description wasn't accurate enough. I have made this screenshot to show the issue. See, the vertical alignment looks strange, and it appears outside the margin. I copy-pasted what you wrote, so I'm not sure what's wrong. –  Gaussler Mar 5 '13 at 23:05
@Gaussler are you sure you pasted my code as is? :) For me it gives the output I posted in my answer- if not, please make it into a complete MWE and add it to your questino –  cmhughes Mar 6 '13 at 1:46
I have now done just that. :-) –  Gaussler Mar 7 '13 at 21:55