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 use a environment called loesung which I created by myself. Now I have a formula in that environment, but I want to have that formulas centered. Not left aligned, here is my code:

%http://tex.stackexchange.com/questions/69043/center-formula-in-self-created-environment
\documentclass{book}

\usepackage[ngerman]{babel}
%\usepackage{geometry}
%\geometry{left=4cm,right=3cm, top=2cm, bottom=2cm} 
\usepackage{amsmath,amsthm}
\usepackage{mdframed}
\usepackage{xcolor}
\usepackage{hyperref}[2011/02/05]

\definecolor{cloesung}{rgb}{0.972,0.93725,0.85098}

\newtheoremstyle{mystyle2}
  {\topsep}{\topsep}{}{}%
  {\bfseries}{}{.5em}{}%

\newmdtheoremenv[hidealllines=true,
backgroundcolor=cloesung,skipabove=\topsep,
skipbelow=\topsep]{loesung}{L\"osung}

\begin{document}

\begin{loesung}\text{blafasel}\\
\begin{align*}
c &= a+b\\
\intertext{description} a+b \intertext{is ....}
d &= h+g
\end{align*}
\end{loesung}

\end{document}

So my problem is, that the formulas should be centered? How can I do this? I tried \centering and \begin{center} but it does not work?

Thanks a lot cya

share|improve this question
1  
Welcome to TeX.SX! Please add a fully compilable minimal working example (MWE) that illustrates your problem. Your code gives Undefined control sequence. l.64 newmdtheoremenv. Also it has to be $a+b$ instead of &a+b&. Usually equations should be centered by default and only left aligned if amsmath gets the option fleqn. –  canaaerus Aug 27 '12 at 19:57
    
well thanks a lot for your help, but my example is what I have? I implemented the mdframed package, so newmdtheoremenv should not be an undefinde control sequence? And I did not use the option fleqn on amsmath...... –  StochastiprocStu Aug 27 '12 at 20:00
1  
Did you look at the two solutions below? –  canaaerus Aug 27 '12 at 20:15
2  
Independent from the actual problem it can cause problems to call two packages with nearly same functions. Check your packages you call: why xcolor two times and color? For a good MWE there is no need for packages like bookmark, xcolor and so on. –  Kurt Aug 27 '12 at 20:16
1  
Since you are using \listfiles, process the exact example code you posted in your question, and then upload elsewhere the obtained .log file; add a comment here providing the link to the .log file so we can have a look at it. –  Gonzalo Medina Aug 27 '12 at 20:39
show 8 more comments

2 Answers

Your problem has nothing to do with your self-created environment. Witness

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\hrule
\begin{align*}
  c &= a+b\\
  \intertext{description} a+b \intertext{is \dots}
  d &= h+g
\end{align*}
\hrule
\end{document}

Unaligned output

So what you are really asking is how to do you center one equation in the middle of an alignment. That can be acheived by putting the extra equation inside the \intertext command in its own maths environment as follows:

\begin{align*}
  c &= a+b\\
  \intertext{description \begin{equation*} a+b \end{equation*} is \dots}
  d &= h+g
\end{align*}

Centered output

Put into your sample environment this looks like:

Sample output

However, I would generally avoid such widely separated alignments and write your example simply as

\begin{loesung}
  blafasel
  \begin{equation*}
c = a+b
\end{equation*}
description
\begin{equation*}
  a+b
\end{equation*}
is \dots
\begin{equation*}
d = h+g
\end{equation*}
\end{loesung}

Simpler output

share|improve this answer
add comment

I think that what you want is possibly this:

\begin{loesung}
\text{ }\\
\begin{align*}
c&=a+b\\
\intertext{description}
a+b\\ 
\intertext{is \dots}
d&=h+g
\end{align*}
\end{loesung}

enter image description here

share|improve this answer
    
no? I just want the c=a+b and the d=h+g in the middle of the page, not on the left side. And my problem is, that now it is on the left side and not in the middle..... –  StochastiprocStu Aug 27 '12 at 20:21
    
@HStudUFD -- The code above already centers both c=a+b and d=h+g on their respective lines. I've added an image file the output that results from the (modified) MWE. –  Mico Aug 27 '12 at 20:53
    
yeah ! the picture is right! but on my pdf the formula is on the left side as the words description and is...? –  StochastiprocStu Aug 27 '12 at 21:16
    
The image above is generated with the code shown, and absolutely nothing else. If your TeX distribution doesn't generate this output as well, then there must be something wrong with your TeX distribution's setup or implementation. Please indicate which TeX distribution you use: TeXLive (2012? 2011?), MikTeX (2.9?, 2.8?), or something else? When was the last time you updated the LaTeX packages you load in the (not so minimal!) code example you provide? –  Mico Aug 27 '12 at 21:21
    
ok I am working on getting a better minimal code, I uploaded the packages just a few days ago, 5 days perhaps, I use Miktex 2.9 and viewing and editing it with TexWorks 0.4.4 r1003 –  StochastiprocStu Aug 27 '12 at 21:28
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.