I want an example environement that put Example 1.2 in the margin (bold) Text of example in the textwidth, Solution in the margin (italics) and the text of solution in the text width.
2 Answers
Solution 1
Here's something to get you going using the ntheorem
package.
% arara: pdflatex
\documentclass{article}
\usepackage{ntheorem} % needed for theorems, examples- MUST load AFTER amsmath
\usepackage{lipsum}
\makeatletter
\newtheoremstyle{margincmh}%
{\item[\theorem@headerfont \llap{##1 ##2}]}%
{\item[\theorem@headerfont \llap{##1 ##2} -- ##3\theorem@separator\hskip\labelsep]}%
\newtheoremstyle{margincmhsoln}%
{\item[\theorem@headerfont \llap{##1}]}%
{\item[\theorem@headerfont \llap{##1} (##3): ]}%
\makeatother
% example
\theoremstyle{margincmh}
%\theorembodyfont{\itshape}}
\theorembodyfont{}
\theoremsymbol{}
\theoremprework{\medskip}
\theorempostwork{}
\theoremseparator{:}
\newtheorem{myexample}{example}
% solution
\theoremstyle{margincmhsoln}
\theorembodyfont{}
\theoremheaderfont{\itshape}
\theoremprework{\medskip}
\theoremseparator{}
\newtheorem{mysolution}{Solution}
\begin{document}
\begin{myexample}
\lipsum[1]
\end{myexample}
\begin{mysolution}
\lipsum[2]
\end{mysolution}
\end{document}
Solution 2
Alternatively, if you'd prefer to make the environment yourself without a theorem package, you can create it as a simple list
- I have used the enumitem
package to help with the margins
% arara: pdflatex
\documentclass{article}
\usepackage{lipsum}
\usepackage{enumitem}
\newcounter{myexample}
\newenvironment{myexample}{\refstepcounter{myexample}\itemize[leftmargin=0mm]\item[\bfseries example \themyexample]}{\enditemize}
\newenvironment{mysolution}{\itemize[leftmargin=0mm]\item[\itshape Solution]}{\enditemize}
\begin{document}
\begin{myexample}
\lipsum[1]
\end{myexample}
\begin{mysolution}
\lipsum[1]
\end{mysolution}
\end{document}
-
@RaffaeleSantoro glad it helped! if you feel that my answer has been useful, you can feel free to upvote it using the arrows- this gives me reputation, which is the currency of the site :) if it answers the question completely to your satisfaction, you can consider accepting my answer using the green mark (but you might like to wait a day or so in case any other answers appear) :)– cmhughesOct 20, 2013 at 21:37
-
If I have large outer margins (even and odd pages) how I can realise this correctly in both pages? Dec 21, 2013 at 17:53
Here is a possibility with exsheets
:
\documentclass{article}
\usepackage[load-headings]{exsheets}
\SetupExSheets{
counter-within = section ,
headings = margin ,
counter-format = se.qu
}
\RenewQuSolPair
{question}
{solution}[print][headings-format=\itshape]
\usepackage{lipsum}% dummy text
\begin{document}
\section{Foo}
\begin{question}
\lipsum[1]
\end{question}
\begin{solution}
\lipsum[2]
\end{solution}
\end{document}
Hiding the number of the solution is possible but requires a little bit more work:
\documentclass{article}
\usepackage[load-headings]{exsheets}
\DeclareInstance{exsheets-heading}{margin-no-nr}{default}{
runin = true ,
title-post-code = \space ,
attach = { main[l,vc]title[r,vc](0pt,0pt) }
}
\SetupExSheets{
counter-within = section ,
counter-format = se.qu
}
\RenewQuSolPair
{question}[name=Example][headings=margin]
{solution}[print][headings=margin-no-nr,headings-format=\itshape]
\usepackage{lipsum}% dummy text
\begin{document}
\section{Foo}
\begin{question}
\lipsum[1]
\end{question}
\begin{solution}
\lipsum[2]
\end{solution}
\end{document}
-
My Textstudio dont charge \usepackage[load-headings]{exsheets} Oct 20, 2013 at 22:08
-
You probably mean TeXstudio which is an editor and not a TeX distribution. The first public version of
exsheets
on CTAN was2012/10/05 v0.2
so this probably means that your TeX distribution is outdated.– cgniederOct 20, 2013 at 22:11