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.)
Best Answer
This is pretty straight forward with
mdframed
. You can use (for example)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,
A complete MWE follows