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.

Does anybody know how to set the background-color of a framed element?

\begin{framed}       
    Let me have a background :( 
\end{framed}
share|improve this question
1  
switch to mdframed package instead. Can do a lot more including frames and colored bgs with easy configuration. –  daleif Jul 15 at 12:45
    
BTW: next time please provide a minimal example so we can see what kind of preamble you are using –  daleif Jul 15 at 12:45
    
Besides framed and mdframed there is also tcolorbox to create colored boxes. –  Thomas F. Sturm Jul 15 at 16:13

3 Answers 3

up vote 5 down vote accepted

Using the mdframed package defining the background colour is pretty easy:

\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}

\begin{document}

    test

    \begin{mdframed}[backgroundcolor=blue!20] 
        In any right triangle, the area of the square whose side is the hypotenuse is equal to the sum of the areas of the squares whose sides are the two legs.
    \end{mdframed}

\end{document}

enter image description here

share|improve this answer

The package documentation is your friend.

\documentclass{article}
\usepackage{xcolor}
\usepackage{framed}
\definecolor{shadecolor}{rgb}{1,0,0}
\begin{document}
\begin{shaded*}
    Let me have a background :(
\end{shaded*}
\end{document}

colour

share|improve this answer
1  
With this solution the frame border is lost –  Frank Roth Jul 15 at 12:52
    
@Ian Thompson: If you load xcolor with, say, the x11names option, you can use \colorlet{shadecolor}{Red1}, which one may find a more expressive syntax. –  Bernard Jul 15 at 13:56

Two solutions with the framed package with a frameborder and a framecolor: I define the frshaded and fgshaded* environments. Rule thickness and distance between text and frame can be easily changed.

    \documentclass [a4paper,12pt]{article}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage[x11names]{xcolor}
    \usepackage{framed}
    \colorlet{shadecolor}{LavenderBlush2}
    \colorlet{framecolor}{Red1}
    \usepackage{lipsum}

    \newenvironment{frshaded}{%
    \def\FrameCommand{\fboxrule=\FrameRule\fboxsep=\FrameSep \fcolorbox{framecolor}{shadecolor}}%
    \MakeFramed {\FrameRestore}}%
    {\endMakeFramed}

    \newenvironment{frshaded*}{%
    \def\FrameCommand{\fboxrule=\FrameRule\fboxsep=\FrameSep \fcolorbox{framecolor}{shadecolor}}%
    \MakeFramed {\advance\hsize-\width \FrameRestore}}%
    {\endMakeFramed}

    \begin{document}

    Text text text text text text text text text text text text text text text text text text text text. text text text text text

    \begin{frshaded}
    \lipsum[1-2]
    \end{frshaded}
    \colorlet{framecolor}{VioletRed4}
    \setlength\FrameRule{1.5pt}
    \begin{frshaded*}
    \lipsum[1-2]
    \end{frshaded*}

    \end{document} 

enter image description here

enter image description here

share|improve this answer

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.