11

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}
2
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – user11232
    Apr 13, 2015 at 7:22
  • Please always add a minimal working example (MWE)
    – user11232
    Apr 13, 2015 at 7:24

1 Answer 1

11

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

3
  • Harish, both your solutions are valid for my document. However, there is one problem: how to make the quote block flow into the next page. It appears both solutions are trying hard to keep the blocks on the same page and they are messing up vertical spacing in-between paragraphs surrounding the quote. I'm unsure if this calls for posting another question.
    – Emacs User
    Apr 13, 2015 at 18:32
  • 1
    @EmacsUser In your approach using \colorbox (second one in the answer), breaking across pages is not possible. That is why I recommended tcolorbox. In my tcolorbox solution, just add breakable to the options like ...boxsep=0pt,breakable}
    – user11232
    Apr 13, 2015 at 23:25
  • Adding \usepackage[most]{tcolorbox} does not work for me, I had to remove the [most] option, otherwise pdflatex always fails. Additionally I had to remove the breakable from the newtcolorbox definition.
    – Robert
    Mar 26, 2021 at 14:41

You must log in to answer this question.

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