In a recent post (http://www.latex-community.org/forum/vi ... =5&t=12144), i pointed out a referencing problem with \newenvironment, regarding the book class. With help by gmedina (thanks) i have managed to create a new environment for the examples of a book and also to create a \listofexamples. Now that the book is finished and all the \label's and \ref's work fine, one problem still insists bugging me.
I include an example code for discussion.
Code: Select all
\documentclass[11pt,a4paper,notitlepage,fleqn]{book}
% define example counter
%---------------------------
\newcounter{exampleC}[chapter]
\renewcommand\theexampleC{\thechapter.\arabic{exampleC}}
% define example environment
%---------------------------
\usepackage{relsize} % for setting smaller fonts in the example environment
\newenvironment{example}[1]%
{\refstepcounter{exampleC}%
\addcontentsline{xmp}{example}{\theexampleC~~#1}% add the entry to the new list
\vspace{\baselineskip}\par%
\begin{quote}%
\noindent\smaller%
\textbf{Example~\theexampleC~~#1}
\end{quote}%
\par\begin{quotation}\smaller%
}
{\end{quotation}\noindent}
% define List of Examples
%---------------------------
\newcommand\listexamplename{List of Examples}
\makeatletter
\newcommand\listofexamples{\chapter{\listexamplename}\@starttoc{xmp}}
\newcommand\l@example{\@dottedtocline{1}{1.5em}{2.3em}}
\makeatother
% activate references
%---------------------------
\usepackage[hypertex]{hyperref}
\begin{document}
\frontmatter
\tableofcontents
\listofexamples
\mainmatter
\chapter{I am the first chapter}\label{Ch:01}
Here's an example
\begin{example}{I am the first example of the first chapter}\label{ex:1.1}
example text....
\end{example}
Go to Example~\ref{ex:2.2}
\newpage
And here's another example
\begin{example}{I am the second example of the first chapter}\label{ex:1.2}
example text....
\end{example}
\chapter{I am the second chapter}\label{Ch:02}
Here's an example
\begin{example}{I am the first example of the first chapter}\label{ex:2.1}
example text....
\end{example}
\newpage
And here's another example
\begin{example}{I am the second example of the first chapter}\label{ex:2.2}
example text....
\end{example}
Go to Example~\ref{ex:1.1}
\end{document}
Code: Select all
\contentsline {example}{1.1\nobreakspace {}\nobreakspace {}I am the first example of the first chapter}{1}{exampleC.1}
\contentsline {example}{1.2\nobreakspace {}\nobreakspace {}I am the second example of the first chapter}{2}{exampleC.2}
\contentsline {example}{2.1\nobreakspace {}\nobreakspace {}I am the first example of the first chapter}{3}{exampleC.1}
\contentsline {example}{2.2\nobreakspace {}\nobreakspace {}I am the second example of the first chapter}{4}{exampleC.2}
Code: Select all
\contentsline {example}{1.1\nobreakspace {}\nobreakspace {}I am the first example of the first chapter}{1}{exampleC.1.1}
\contentsline {example}{1.2\nobreakspace {}\nobreakspace {}I am the second example of the first chapter}{2}{exampleC.1.2}
\contentsline {example}{2.1\nobreakspace {}\nobreakspace {}I am the first example of the first chapter}{3}{exampleC.2.1}
\contentsline {example}{2.2\nobreakspace {}\nobreakspace {}I am the second example of the first chapter}{4}{exampleC.2.2}