Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using a \newtheoremstyle to generate a \newtheorem called Example. However, I want the Example (the theorem) and the text, everything, to have a smaller text width than the normal text, and I don't know the efficient way of doing this, and avoid repeating code each time.

Is there an intelligent way to do this in the \newtheoremstyle? Or elsewhere?

share|improve this question
    
Note that it is unusual around here to have any greeting. –  lockstep Feb 26 '11 at 18:05
add comment

1 Answer 1

The thmtools package can help with this.

\documentclass{article}
\usepackage{amsthm,thmtools}
\usepackage{xcolor}
\usepackage{lipsum}
\declaretheorem[shaded={bgcolor=white,textwidth=20em},style=definition]{Example}
\begin{document}
\lipsum[1]
\begin{Example}
\lipsum[2]
\end{Example}
\end{document}

This puts the Example is a box that is 20em wide.

enter image description here

Edit:
In a comment, you mention centering for the first time. Here's a way to get centering. It takes a little bit more work.

\documentclass{article}
\usepackage{amsthm,thmtools}
\usepackage{lipsum}
\declaretheorem[style=definition]{Example}
\addtotheorempreheadhook[Example]{%
        \moveright\dimexpr(\linewidth-20em)/2\vbox\bgroup
                \hsize=20em
                \linewidth=\hsize
}
\addtotheorempostfoothook[Example]{\egroup}
\begin{document}
\lipsum[1]
\begin{Example}
\lipsum[2]
\end{Example}
\end{document}

This doesn't rely on the shaded extension. Instead, it puts the theorem in a \vbox of the appropriate size and then moves that right (\linewidth-20em)/2.

share|improve this answer
    
Thanks, this looks like a great solution. However, I'm looking at the Thmtools Users’ Guide and can't find anything about centering that example. I want exactly what you posted, but centered. How can I do this? –  Paul Feb 26 '11 at 18:45
    
@Paul: I've added a way to get centering. –  TH. Feb 26 '11 at 19:22
    
thanks for your suggestions, but I find really complicated the installation of thmtools on windows. I haven't been able to implement this yet. –  Paul Mar 4 '11 at 13:36
    
@Paul: I cannot help with that. I only rarely use Windows and never TeX on Windows. All I can say is it comes with TeX Live. –  TH. Mar 4 '11 at 21:05
    
@TH: MikTeX works seamlessly with Windows, both its 32-bits and its 64-bits. It includes and installs thmtools –  Peter Jones Sep 24 '11 at 10:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.