# [Tex/LaTex] Help with a framed environment

framed

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}%
}%
\MakeFramed {\advance\hsize -\width \FrameRestore}}%
{\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.)

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}