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[hidelinks]{hyperref}
\usepackage{cleveref}
\usepackage[ansinew]{inputenc}
\usepackage{wasysym}
\usepackage{tipa,vowel,textcomp}
\chapterstyle{veelo}
\pagestyle{headings}
\usepackage[amsmath]{ntheorem} % for theorem-like environments
% margin theorem
\makeatletter
\newtheoremstyle{mymargin}%
{\item[\theorem@headerfont \llap{##1 ##2}]}%
{\item[\theorem@headerfont \llap{##1 ##2}| ##3\theorem@separator\hskip\labelsep]}%
\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? :-)

example 0.0.1at 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 05 '13 at 22:34