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.

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?

share|improve this question
    
By colouring the frame you mean the border or the background or both? –  ArTourter Jul 18 '12 at 13:07
    
Just the border –  Joseph Elcid Jul 18 '12 at 13:13
    
Perhaps you should consider using the mdframed package. –  user2473 Jul 18 '12 at 13:14
    
Have you had a look at the mdframed package? –  ArTourter Jul 18 '12 at 13:23
1  
You could also try the tcolorbox package. –  Claudio Fiandrino Jul 18 '12 at 13:24

2 Answers 2

up vote 8 down vote accepted

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

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

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

share|improve this answer
    
Pretty! The thicker lines make the colors more vivid! –  Joe Corneli Dec 11 '12 at 0:50

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.