General ⇒ Examples in LaTeX Companion
Examples in LaTeX Companion
I often browse through The LaTeX Companion (I still need help!) and now I would like to number the examples of one of my document using the same method used by TLC's authors, but in this book I didn't succeed to get any explaination (I've browsed this forum, too).
Can someone help me?
Thanks a lot,
Nino
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Re: Examples in LaTeX Companion
how exactly are you building your examples? Are you using a custom environment, or some environment defined with the help of amsthm? Please post a minimal compilable example of the code that you are using to create your examples.
Examples in LaTeX Companion
now I'm using ntheorem, but I would like to adopt the style used by TLC's authors. It seems to be a modified equation environment.
I attach a screenshot of one example taken from that book:
As you can see at the end (or at the beginning in an odd page) of the last line of the example there is a label with the chapter and section numbers followed by a progressive number.
Thanks,
Nino
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker
Examples in LaTeX Companion
the code below shows how to proceed schematically:
Code: Select all
\documentclass[openany]{book}
\usepackage{chngcntr}
% creating the counter
\newcounter{exmpl}
% subordinating the new counter to sections; requires the chngcntr package
\counterwithin{exmpl}{section}
% redefining the counter. Format: chapter-section-exmpl
\renewcommand\theexmpl{\arabic{chapter}--\arabic{section}--\arabic{exmpl}}
% defining the environment for examples
\newenvironment{myexample}
{\stepcounter{exmpl}\noindent}
{\marginpar{\fbox{\theexmpl}}\vskip1em}
\begin{document}
\chapter{Test chapter one}
\section{Test section one one}
\begin{myexample}
Test example one
\end{myexample}
\begin{myexample}
Test example two
\end{myexample}
\section{Test section one two}
\begin{myexample}
Test example three
\end{myexample}
\chapter{Test chapter two}
\section{Test section two one}
\begin{myexample}
Test example four
\end{myexample}
\end{document}
Re: Examples in LaTeX Companion
I'm a little frustrated because I'm not able to solve this type of problems

Thank you again,
Nino
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker
Examples in LaTeX Companion
your code works very well, but I've tried to modify ntheorem command too

Code: Select all
\makeatletter
\renewtheoremstyle{marginbreak}%
{\item[\rlap{\vbox{\hbox{ \theorem@headerfont \llap{\fbox{##1 ##2}} \hskip\labelsep\relax \theorem@separator} \hbox{\strut}}}]} {\item[\rlap{\vbox{\hbox{\theorem@headerfont
\llap{\fbox{##1 ##2}}\hskip\labelsep\relax\
##3\theorem@separator}\hbox{\strut}}}]}
\makeatother
Now the problem is that I don't know how to modify the quoted code to get the label on the right or on the left according to the page number, as your code does.
Can you help me again?
Thanks,
Nino
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker
Re: Examples in LaTeX Companion
I will need some minimal compilable code, showing all the settings for the new environment that you defined.
Examples in LaTeX Companion
Code: Select all
\documentclass[10pt,a4paper,twoside,cp1256,utf8x]{book}
\usepackage[thref]{ntheorem}
\makeatletter
\renewtheoremstyle{marginbreak}%
{\item[
\rlap{
\vbox{
\hbox{
\theorem@headerfont
\llap{\fbox{##1 ##2}}
\hskip
\labelsep
\relax
\theorem@separator}
\hbox{\strut}
}
}
]
}
{\item[\rlap{\vbox{\hbox{\theorem@headerfont
\llap{\fbox{##1 ##2}}\hskip\labelsep\relax\
##3\theorem@separator}\hbox{\strut}}}]}
\makeatother
\theoremstyle{marginbreak}
%\theoremstyle{plain}
\theoremheaderfont{\normalfont\bfseries}\theorembodyfont{\slshape}
\theoremsymbol{\ensuremath{\clubsuit}}
\theoremseparator{:}
\newtheorem{reg}{Ex.}
\begin{document}
\chapter{Test chapter one}
\section{Test section one one}
\begin{reg}[Test 01]\label{t01}
Test example one
\end{reg}
\begin{reg}[Test 02]\label{t02}
Test example two
\end{reg}
\section{Test section one two}
\begin{reg}[Test 03]\label{t03}
Test example three
\end{reg}
\chapter{Test chapter two}
\section{Test section two one}
\begin{reg}[Test 04]\label{t04
Test example four
\end{reg}
\end{document}
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker
Examples in LaTeX Companion
Code: Select all
\documentclass[10pt,a4paper,twoside]{book}
\usepackage[thref]{ntheorem}
\usepackage{ifthen}
\makeatletter
\newcounter{pl}
\renewtheoremstyle{marginbreak}%
{\stepcounter{pl}\label{pl-\thepl}%
\item[\rlap{\vbox{\hbox{\theorem@headerfont
\llap{\fbox{##1 ##2}}\hskip\labelsep\relax
\theorem@separator}\hbox{\strut}}}]
}
{\stepcounter{pl}\label{pl-\thepl}%
\ifthenelse{\isodd{\pageref{pl-\thepl}}}
{\item[\rlap{\vbox{\hbox{\theorem@headerfont
\llap{\fbox{##1 ##2}}\hskip\labelsep\relax\
##3\theorem@separator}\hbox{\strut}}}]
}
{\item[\hskip1.7cm\llap{\vbox{\hbox{\theorem@headerfont
\rlap{\hspace{1.1\textwidth}\fbox{##1 ##2}}\hskip\labelsep\relax\
##3\theorem@separator}\hbox{\strut}}}]\hskip-1.7cm%
}
}
\makeatother
\theoremstyle{marginbreak}
\theoremheaderfont{\normalfont\bfseries}\theorembodyfont{\slshape}
\theoremsymbol{\ensuremath{\clubsuit}}
\theoremseparator{:}
\newtheorem{reg}{Ex.}
\begin{document}
text text text text text text text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text
\begin{reg}[Test 01]\label{t01}
Test example one
\end{reg}
\newpage
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
\begin{reg}[Test 02]\label{t02}
Test example two
\end{reg}
\end{document}
Flushleft and flushright in margins (odd an even pages)?
you will find an explanation of the machanism used in my example code to control the aspect of the environment depending on the page parity.
2) Of course, my code is just an example and, as such, admits improvements; feel free to adapt it according to your needs.
Re: Examples in LaTeX Companion

Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker