[Tex/LaTex] Colored frame for the framed environment

colorframed

I'm using the framed environement to put a text in a framed box. I'm using it because I like its formating more than fbox. Now I would like to color the frame's border and I didn't find anything on the net to do that.

How should I proceed?

Best Answer

As others have mentioned, the mdframed package allows you to obtain a colored frame in an easy way through the linecolor=<color> option. A complete example:

\documentclass{article}
\usepackage{mdframed}
\usepackage{lipsum}

\begin{document}

\begin{mdframed}[linecolor=blue]
\lipsum[4]
\end{mdframed}\medskip
\begin{mdframed}[linecolor=red]
\lipsum[4]
\end{mdframed}\medskip
\begin{mdframed}[linecolor=green]
\lipsum[4]
\end{mdframed}

\end{document}

enter image description here

A solution using the framed package is also easy to achieve. You can define a new environment to give a color to the frame; in the following example, I defined the cframed environment to draw a colored frame around the text. The new environment simply defines \FrameCommand to use a \fcolorbox; the default frame color is blue and can be changed using an optional argument for the environment:

\documentclass{article}
\usepackage{framed}
\usepackage{xcolor}
\usepackage{lipsum}

\newenvironment{cframed}[1][blue]
  {\def\FrameCommand{\fboxsep=\FrameSep\fcolorbox{#1}{white}}%
    \MakeFramed {\advance\hsize-\width \FrameRestore}}
  {\endMakeFramed}

\begin{document}

\begin{cframed}
\lipsum[4]
\end{cframed}
\begin{cframed}[red]
\lipsum[4]
\end{cframed}
\begin{cframed}[green]
\lipsum[4]
\end{cframed}
\lipsum[4]

\end{document}

enter image description here