\begin{framed} 带背景颜色

\begin{framed} 带背景颜色

有人知道如何设置框架元素的背景颜色吗?

\begin{framed}       
    Let me have a background :( 
\end{framed}

答案1

如果使用以下包,定义背景颜色非常容易mdframed

\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}

在此处输入图片描述

答案2

包装文档是你的朋友。

\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}

颜色

答案3

framed带有 aframeborder和 a 的包的两个解决方案framecolor:我定义了frshadedfrshaded*环境。可以轻松更改规则厚度和文本与框架之间的距离。

    \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} 

在此处输入图片描述

在此处输入图片描述

相关内容