# Wrong width of environment after includegraphics

I have created an own environment with the mdframed package. My problem is, if I insert a picture in the self defined envrionment, the width of the color box is wrong.

Here is the code:

\documentclass{book}
\usepackage{geometry}

\geometry{left=4cm,right=3cm, top=2cm, bottom=2cm}
\usepackage[ngerman]{babel}
\usepackage{mathptmx}
\usepackage{helvet}
\usepackage{wallpaper}
\usepackage[final]{pdfpages}
hypertexnames=TRUE,pdfpagelabels=true]{hyperref}[2011/02/05]

\usepackage{xcolor,bookmark}
\usepackage{scrextend}
\usepackage{titlepic}
\usepackage{shorttoc}
\usepackage{courier}
\usepackage{type1cm}
\usepackage{zref-abspage}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage[bottom]{footmisc}
\usepackage{tocstyle}
\usetocstyle{allwithdot}
\usepackage{thmbox}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{marginnote}
\usetocstyle{KOMAlike}
\usepackage{wrapfig}
\usepackage{paralist}
\usepackage{mdframed}
\makeindex

\definecolor{aufgaben}{rgb}{0.9333,0.93333,0.933333}%
\definecolor{loesung}{rgb}{0.972,0.93725,0.85098}
\definecolor{textbeispiel}{rgb}{0.86666,0.78431,0.78431}

\newtheoremstyle{mystyle}
{\topsep}{\topsep}{}{}%
{\bfseries}{:}{.5em}{}%

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

\theoremstyle{mystyle}

skipbelow=\topsep]{beispiel}{Beispiel}

\newmdtheoremenv[hidealllines=true,
skipbelow=\topsep]{formel}{Formel}

\theoremstyle{mystyle2}

\newmdtheoremenv[hidealllines=true,
backgroundcolor=aufgaben,skipabove=\topsep,
skipbelow=\topsep]{aufgabe}{Aufgabe}

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

\begin{document}
\begin{loesung}
\includegraphics[scale=0.5]{histloesungzeichnung.png}\\
c)\\
Here comes a lot of text which describes different things, but this complete area should have the same color background width as the solution below! : $\bar{x}=\frac{1}{99}(18*1.5+20*3.5+25*5+22*7+14*9)$
\end{loesung}
\begin{loesung}
here comes the next solution with the correct width of the color background box!
\end{looesung}
\end{document}


How can I make the color box has the same width?

Also a general question: If I try to include a float figure, it does not work. It seems to me, that this is in general not possible, to include a float figure in the self defined environment loesung. Also a table is not possible (but tabular). Any ideas on this? The error message if I use figures in the loesung environment is Float(s) lost.

I am writing on a larger document, so I have this problem several times and it really rips me of. I solved the other problems with just using tabular, but here in this case, I really need the picture there to be included.

Thanks a lot!

I attached a screenshot of my problem (I changed the text, so you can better understand the problem, the changing of the text does not matter), I have no account so I have to give you the screenshot:

-
Your example code doesn't compile; the thmbox and amsthm packages conflict; also, there's a typo in \end{looesung} (it should be \end{loesung}). – Gonzalo Medina Aug 27 '12 at 21:33
floats can not go in boxes, but boxes can go in floats – cmhughes Aug 27 '12 at 21:35
@GonzaloMedina it was in response to, 'Also a general question'... – cmhughes Aug 27 '12 at 21:43
well, first of all thanks a lot, but if I change it to \textwidth it is getting a bit more width but it is still not correct! and to the general question: What does that mean "boxes can go in floats", how can I add a figure in a loesung environment? – StochastiprocStu Aug 28 '12 at 8:04

In the \includegraphics instruction, don't use [scale=0.5]; instead, use [width=\textwidth].
Separately, two humble requests: 1. When posting a minimum working example, please eliminate all typos (see: \end{looesung}); do note the word "working" in the term "minimum working example". 2. Please also avoid loading any and all packages in the MWE that are aren't strictly needed to illustrate and/or replicate the problem at hand.