1

I want to define an environment with appointed color, that is to say the whole environment from the \begin{env} to \end{env} will be drawed by the color. Just like a code block. Roughly, this is waht I expect.

enter image description here

I tried to use \colorbox, but it seemed that the box didn't support for multiple lines of text. For instance, I have a costomized environment myenv, then how can I realize what I expect.

\documentclass{article}

\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{framed}

\newenvironment{myenv}{%
    %\colorbox{gray}
    \medskip
    \begin{quote}
        \centering
}{\end{quote}\medskip}

\begin{document}
    \section{A}
    \lipsum{1}
    \begin{myenv}
        \lipsum{2}
    \end{myenv}
    \lipsum{3}\par
    {\centering
    \colorbox{gray}{AAAAAA}
\end{document}

Please give me an example. Thanks.

2

2 Answers 2

3

If you want to stay with framed.sty package, then try with the below MWE:

\documentclass{article}

\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{framed}
\definecolor{shadecolor}{cmyk}{0,0,0,0.5}%change what ever you like

\newenvironment{myenv}{%
    %\colorbox{gray}
    \medskip
    \begin{shaded*}
        \centering
}{\end{shaded*}\medskip}

\begin{document}
    \section{A}
    \lipsum{1}
    \begin{myenv}
        \lipsum{2}
    \end{myenv}
    \lipsum{3}\par
    {\centering
    \colorbox{gray}{AAAAAA}
\end{document}

Apart from this, tcolorbox.sty and mdframed.sty also having nice features...

1
\documentclass{article}

\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\newenvironment{myenv}{%
  \begin{tcolorbox}[colback=gray, breakable, sharp corners]
    \medskip
    \begin{quote}
        \centering
}{\end{quote}\medskip\end{tcolorbox}}

\begin{document}
    \section{A}
    \lipsum{1}
    \begin{myenv}
        \lipsum{2}
    \end{myenv}
    \lipsum{3}\par
    {\centering
    \colorbox{gray}{AAAAAA}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .