[Tex/LaTex] how to eliminate the horizontal spacing of the frame in the framed package

framedspacing

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}
\definecolor{shadecolor}{rgb}{.9, .9, .9}
\newenvironment{myframe}{%
\def\FrameCommand{\fboxsep=\FrameSep \colorbox{shadecolor}}%
\MakeFramed {\hsize\linewidth\advance\hsize-\width \FrameRestore}}%
{\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:

http://i.stack.imgur.com/VR1SF.png

Best Answer

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}
\definecolor{shadecolor}{rgb}{.9, .9, .9}
\makeatletter

\renewenvironment{snugshade}{%
 \def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
 \colorbox{shadecolor}{##1}\hskip-\fboxsep
     % There is no \@totalrightmargin, so:
     \hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
 \MakeFramed {\advance\hsize-\width
   \@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
    \begin{snugshade}
def
    \end{snugshade}
  \end{enumerate}
\end{document}

enter image description here