[Tex/LaTex] Change background color for text block

backgroundsenvironments

I want to change the style for \quote areas in my entire document. These three lines is what I came up with. Font and margins changes take effect but not the bg color. Only the first char's bg color changes, not the the entire quote block.

\definecolor{block-gray}{gray}{0.85}

\newenvironment{myblock}
{\small \addtolength{\leftskip}{10mm} \addtolength{\rightskip}{10mm} \colorbox{block-gray} } 
{\normalsize \addtolength{\leftskip}{0mm} \addtolength{\rightskip}{0mm}}

\renewcommand{\quote}{\myblock}

Best Answer

For such jobs, tcolorbox is more suitable. The advantage here is the box is breakable across pages.

\documentclass{article}
\usepackage{showframe,lipsum}                    %% just for demo
\usepackage[most]{tcolorbox}
\definecolor{block-gray}{gray}{0.85}
\newtcolorbox{myquote}{colback=block-gray,grow to right by=-10mm,grow to left by=-10mm,
boxrule=0pt,boxsep=0pt,breakable}
\begin{document}
\noindent
  \begin{myquote}
    \lipsum
  \end{myquote}
\end{document}

enter image description here

In your method, you may better use environ package. However, this is not breakable across pages.

\documentclass{article}
\usepackage{xcolor,showframe}
\definecolor{block-gray}{gray}{0.85}

\usepackage{environ}

\NewEnviron{myblock}
{\colorbox{block-gray}{%
\parbox{\dimexpr\linewidth-2\fboxsep\relax}{%
\small\addtolength{\leftskip}{10mm}
\addtolength{\rightskip}{10mm}
\BODY}}
}

\renewcommand{\quote}{\myblock}
\renewcommand{\endquote}{\endmyblock}

\begin{document}
\noindent
  \begin{quote}
    The quote come here The quote come here The quote come here The quote come here The quote come hereThe quote come here The quote come here The quote come here The quote come here
  \end{quote}
\end{document}

enter image description here