16

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?

6
  • By colouring the frame you mean the border or the background or both?
    – ArTourter
    Jul 18, 2012 at 13:07
  • 1
    Just the border Jul 18, 2012 at 13:13
  • Perhaps you should consider using the mdframed package.
    – user2473
    Jul 18, 2012 at 13:14
  • Have you had a look at the mdframed package?
    – ArTourter
    Jul 18, 2012 at 13:23
  • 1
    You could also try the tcolorbox package. Jul 18, 2012 at 13:24

2 Answers 2

14

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

9
  • You can also use \def\FrameCommand{\fboxsep=\FrameSep \color{#1} \fbox} Jul 18, 2012 at 13:55
  • Thanks for your help. Your solution is to be the closest to my question. So I'll accept it Jul 18, 2012 at 13:57
  • @MarcoDaniel: but your suggestion will change the color of both the frame and the contents. Jul 18, 2012 at 14:04
  • @GonzaloMedina I tried the second option you suggested and it changed the foreground color. Jul 18, 2012 at 14:19
  • 1
    @JosephElcid I've updated my answer providing a modified and corrected solution with framed. Jul 18, 2012 at 16:10
6

As Claudio suggested, tcolorbox is another possibility. Here you have Gonzalo's second example, adapted to this package.

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newenvironment{cframed}[1][blue]
  {\begin{tcolorbox}[colframe=#1,colback=white]}
  {\end{tcolorbox}}

\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

1
  • Pretty! The thicker lines make the colors more vivid! Dec 11, 2012 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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