# Help with a framed environment

Upon trying to create a framed environment using the framed package, I stumbled upon a problem I have not been able to resolve. What I am trying to achieve is the following:

Unfortunately with the code:

\documentclass[letterpaper]{article}
\usepackage{xcolor}
\usepackage{calc}
\usepackage{framed}

\newenvironment{defn}[1]{%
\def\FrameCommand{\fboxsep=\FrameSep%
{\color{#1}\hfil\hbox to \hsize{\leaders\hrule height 2pt depth 2pt\hfil}\hfil}\colorbox{yellow!20}%
}%
{\endMakeFramed}
\begin{document}
\begin{defn}{blue}
test test
\end{defn}

\end{document}


I get

The problem is clear, the frame color is correct but the horizontal rule is not being placed correctly. I know that there should be some form of a \vskip or the sort but I cannot get how to put. If this has been asked, please redirect me. I prefer using the framed package (but and mdframed one is welcome.)

-
Is there a reason you prefer framed over mdframed? – clemens Feb 2 '13 at 18:52
No not really but I like the framed package. Just for the challenge. – azetina Feb 2 '13 at 18:56

This is pretty straight forward with mdframed. You can use (for example)

\newmdenv[backgroundcolor=yellow!20,
leftline=false,
rightline=false,
bottomline=false,
linewidth=3pt,
linecolor=blue]{myframe}


If you'd like to have an environment that takes an optional first argument to specify the background colour, then you can use, for example,

\newenvironment{defn}[1][yellow!20]{%
\myframe[backgroundcolor=#1]}
{\endmyframe}


A complete MWE follows

\documentclass{article}
\usepackage[xcolor]{mdframed}
\usepackage{lipsum}

\newmdenv[backgroundcolor=yellow!20,
leftline=false,
rightline=false,
bottomline=false,
linewidth=3pt,
linecolor=blue]{myframe}

\newenvironment{defn}[1][yellow!20]{%
\myframe[backgroundcolor=#1]}
{\endmyframe}
\begin{document}
\begin{defn}[red]
\lipsum[2]
\end{defn}

\lipsum[2]

\begin{myframe}
\lipsum[1]
\end{myframe}

\end{document}

-
Thanks. Definitely looking forward for the framed version. Thanks a lot. – azetina Feb 2 '13 at 18:59
@azetina I posted this because you said an mdframed version is welcome... – cmhughes Feb 2 '13 at 19:00
@cmhughes you beat me by five seconds :) – clemens Feb 2 '13 at 19:01
Yes yes. I appreciate it. I just commented that it would be nice now to see a framed version probably from someone else. Your answer is more than welcomed. – azetina Feb 2 '13 at 19:01
@cgnieder that's happened to me many times :) – cmhughes Feb 2 '13 at 19:02