# how to eliminate the horizontal spacing of the frame in the framed package?

I'm using the framed package and I found it difficult to adjust the width of a frame to adapt to the current environment, e.g. if I use a shaded environment within the enumerate environment, I will get a frame box as wide as the current page (actually slightly wider) -- it will not indent accordingly; then I found a solution to make the frame of the same width as the current environment, but a new problem arised: there seems to be extra horizontal spacing inside the frame. A MWE is below:

\documentclass{article}
\usepackage{framed,color}
\newenvironment{myframe}{%
{\endMakeFramed}

\begin{document}
test a frame within an enumerate environment
\begin{enumerate}
\item abc
\begin{myframe}
def
\end{myframe}
\end{enumerate}
\end{document}


Can anybody tell me how to eliminate the extra left padding so that the content of the frame can align to the list item? Thanks a lot!

A screenshot is here:

-
Thanks for the reminder! I tried to answer directly but got a message box, and I thought it recommended me to edit my original post. I will extract the answer out then. –  Yihui Nov 9 '11 at 1:45

I asked the author of the framed package, and his solution worked for me (although I do not really understand it):

\documentclass{article}
\usepackage{framed,color}
\makeatletter

\def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
% There is no \@totalrightmargin, so:
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
\@totalleftmargin\z@ \linewidth\hsize
\@setminipage}}%
{\par\unskip\endMakeFramed}

\makeatother

\begin{document}
test a frame within an enumerate environment test a frame within an enumerate environment
\begin{enumerate}
\item abc
def
\end{enumerate}
\end{document}


-

I suggest using the mdframed package:

\documentclass{article}
\usepackage{xcolor} % better than color
\usepackage{mdframed}

\begin{document}
test a frame within an enumerate environment
\begin{enumerate}
\item abc
\begin{mdframed}[