[Tex/LaTex] Creating a shaded box with an outline

boxesfloatsframed

EDIT

I'm attempting to create a box with a different background color. However, I've tried this and the box looks unpolished. So I would like to add a line that seperates the two background colors. In other words, the point where the special background color begins and the original document background ends should be seperated by a line that is a third color. I'm wondering how I can accomplish this…

ORIGINAL POST (containing more details)

I don't understand floats very well. I've been using the framed package instead, which is nice because I can easily put a frame around something. There is another behavior included in this package that I'd like to combine. It gives the option to create a shaded environment, which is another way of saying that it changes the background color of the object that I'd like to put a frame around. I really like this, but the edge of the shaded area looks unpolished. So what I'd like to do is to create a float that has a special background color, and I want the edges to have a thin line between the special color and the normal white background that I use for the rest of the document.

I'm using these framed "floats" to display mainly text, so I'd like to know how to combine all of these features. In other words, I'd like to see an example that takes a bunch of text, and gives it a special background with a box that is perfectly aligned at the edge of the background (thus giving it a nice frame). I'd like to see how this can be implemented as a float, as well.

One more thing that isn't necessary, but would be good to know, would be a way to implement similar behavior around an align environment. I don't know if this would require special treatment, but I'd really appreciate it if someone could show me how to do this.

Best Answer

The syntax is \myFloat[optArgs left]{text left}[optArgs right]{text right}{caption}{label} the last two can be empty.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}% only for demo
\usepackage{xcolor,mdframed,caption}
\makeatletter
\def\myFLoat{\@ifnextchar[{\myFloat@i}{\myFloat@i[]}}
\def\myFloat@i[#1]#2{\@ifnextchar[%
  {\myFloat@ii[#1]{#2}}%
  {\myFloat@ii[#1]{#2}[]}}
\def\myFloat@ii[#1]#2[#3]#4#5#6{\par\medskip%
%  \mdfsetup{innerleftmargin=10pt,innerrightmargin=10pt}%
  \noindent\begin{minipage}[t]{0.475\textwidth}\leavevmode
    \begin{mdframed}[#1]#2\end{mdframed}
  \end{minipage}\hfill
  \begin{minipage}[t]{0.475\textwidth}\leavevmode
    \begin{mdframed}[#3]#4\end{mdframed}
   \end{minipage}
  \ifx\relax#5\relax\else\captionof{figure}{#5}\fi%
  \ifx\relax#6\relax\else\label{#6}\fi\par}
\makeatother
\begin{document}

\blindtext
\myFLoat[linecolor=blue,linewidth=2pt,backgroundcolor=yellow]{\blindtext}%
        [linecolor=red,linewidth=3pt]{\blindtext}%
        {my caption for this float}{myLabel}

as seen in my Figure~\ref{myLabel} it works.

\blindtext
\myFLoat[linecolor=blue,linewidth=2pt,backgroundcolor=yellow]{\blindtext}%
        [linecolor=red,linewidth=3pt]{\begin{align}y=\int\limits_1^2 f(x)dx\end{align}}%
        {my caption for this float}{myLabelB}

\end{document}

alt text

alt text