Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

enter image description here

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 enter image description here

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.)

share|improve this question
3  
Is there a reason you prefer framed over mdframed? –  cgnieder 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
add comment

1 Answer

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}

screenshot

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}
share|improve this answer
    
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 :) –  cgnieder 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
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.