2

I would like to know if it's possible right from the definition of a theorem to center it :

\begin{center}
\begin{minipage}{5cm}
{

{
\theoremstyle{plain}
\theorembodyfont{\small}
\theoremheaderfont{\scshape}
\theoremsymbol{C.Q.F.D.}
\newtheorem*{dem}{Démonstration}
}

}
\end{minipage}
\end{center}

The code produces this : enter image description here

My goal is to have all same type of theorem to be centered. Like this :

enter image description here

  • Not using your setup. Instead one could tie into \begin{dem} and \end{dem} (via something like etoolbox). However, could you supply the community with a minimal working example (MWE) that they can work with? It should show the current output as well as your expected output, rather than just code snippets. – Werner Aug 11 '14 at 17:16
  • Sure I will do it. But the fact is that I've seen this effect on a book (written with LaTeX for sure) and I don't really know how to reproduce it. – Le Duc Banal Aug 11 '14 at 17:29
  • For the community's use, wrap the whole thing in a center environment and see what the output looks like. If it works for you, then that could be automated. If it doesn't, explain what should be different and perhaps include a screen shot (picture of some kind) of what it should look like. – Werner Aug 11 '14 at 17:30
  • I added the result of the posted code to explain myself. – Le Duc Banal Aug 11 '14 at 17:44
  • Do you only want indentation on the left? This can be done with \theoremindent <dimension> before \newtheorem*. Notice the lack of curly braces. – René B. Christensen Aug 11 '14 at 18:07
3

You can use etoolbox to tie into the \begin{dem} and \end{dem} components of your theorem:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{ntheorem,etoolbox,changepage,lipsum}

\theoremstyle{plain}
\theorembodyfont{\small}
\theoremheaderfont{\scshape}
\theoremsymbol{C.Q.F.D.}
\newtheorem*{dem}{Démonstration}
% Center theorem with respect to text block (2em indent on both sides)
\AtBeginEnvironment{dem}{\begin{adjustwidth}{2em}{2em}}
\AtEndEnvironment{dem}{\end{adjustwidth}}

\begin{document}
\lipsum[1]
\begin{dem}
\lipsum[2]
\end{dem}
\lipsum[3]
\end{document}

adjustwidth from changepage is a list-like environment which is used to indent from either side and allows for breaking across the page boundary. You can adjust the 2em measure to suit your needs.

  • Exactly what I was searching for ! Thanks a lot for your help ! – Le Duc Banal Aug 11 '14 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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