# What is the simplest, most canonical way to change the background color of quoted text?

There are many questions in this site on changing the background color of quoted text, but I am bewildered and disheartened by the huge proliferation of different ways to do this, each using a different additional package. I can't believe that such a common and conceptually simple task doesn't have one basic, canonical solution. (This solution may be inadequate for specific situations, of course, but only then I would consider bringing in speciallized tools.)

Basically, I'm looking for something analogous in appearance to

this effect (but without the fancy borders, just the background color change)

...or

this effect (but without the change of font or foreground color, just the background color change)


...or preferably somewhere in-between, namely, the simple color change of the latter, but without the change of font.

Doesn't "bare LaTeX" provide a way to do this?

• "bare" latex doesn't have colour at all, so you shouldn't be surprised that a package is needed, it doesn't have figures or tables either but color package is in the core "required" release so it is as canonical as article class, and \colorbox{yellow}{hello} will write that text on a yellow background. – David Carlisle Jun 8 '18 at 22:26
• The idea that using a package is somehow less simple is misguided most of the time. Packages make code simpler because they provide user level interfaces to solve specific problems. There's no obvious advantage to doing everything from basic code (and some clear disadvantages.) – Alan Munn Jun 8 '18 at 22:50
• Whatever you're doing to try to produce different "this effect" examples in the question does not work for me. The first example draws horizontal lines above and below the text (which is just plain text), the second doesn't even have the lines. It's just text in my normal foreground/background colors. – jamesqf Jun 9 '18 at 5:20
• @AlanMunn: My problem is not so much with the use of a package, but with the fact that each solution I find uses a different one. It's as if, when someone asked how to compute logarithms in Python, instead of learning about the single, canonical math module, one found that there dozens of different possible modules to compute logs in Python. – kjo Jun 10 '18 at 3:38
• One step away from python is the R world in which many such choices also can be made. :) But also 'canonical' can change as new packages come up. When I started using TeX qtree was the canonical way to draw trees, then tikz-qtree and now forest. – Alan Munn Jun 10 '18 at 3:47

A simple code based on framed and quoting which can break across pages:

\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{framed}
\usepackage{quoting}

\usepackage{lipsum}
\quoting[leftmargin=0pt, vskip=0pt]
}
{\endquoting
}

\begin{document}

\lipsum*[1-4]
\lipsum*[5-6]
\lipsum*[7-10]

\end{document}


Color support needs xcolor (or just color).

\documentclass{article}
\usepackage{xcolor}

\usepackage{lipsum} % for mock text

\newsavebox{\coloredquotationbox}
\newenvironment{coloredquotation}
{%
\begin{trivlist}
\begin{lrbox}{\coloredquotationbox}
\begin{minipage}{\dimexpr\linewidth-2\fboxsep}
}
{%
\end{minipage}
\end{lrbox}
\item\relax
\parbox{\linewidth}{
\begingroup
\color[RGB]{224,215,188}%
\hrule
\color[RGB]{249,245,233}%
\hrule
\color[RGB]{224,215,188}%
\hrule
\endgroup
\colorbox[RGB]{249,245,233}{\usebox{\coloredquotationbox}}\par\nointerlineskip
\begingroup
\color[RGB]{224,215,188}%
\hrule
\color[RGB]{249,245,233}%
\hrule
\color[RGB]{224,215,188}%
\hrule
\endgroup
}
\end{trivlist}
}

\begin{document}

\lipsum*[3]
\begin{coloredquotation}
\lipsum*[4]
\end{coloredquotation}
\lipsum*[5]

\end{document}


• @kjo should be aware (as of course you are) that this will not break across pages, which is one of the reasons why package solutions such as tcolorbox exist. – Alan Munn Jun 8 '18 at 22:45
• Thanks! Even though I used this site's quotation look as a convenient example, it is far fancier than I need. In particular, the top and bottom rules for the quotation box are unnecessary. IMO, this answer would be greatly improved if the solution were simplified as much as possible, by removing the top and bottom rules. IOW, the difference between the quoted and unquoted text could be as minimal as only a change in the background color. – kjo Jun 13 '18 at 15:01

An example with tcolorbox (is not almost canonical?) was missing.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\definecolor{linequote}{RGB}{224,215,188}
\definecolor{backquote}{RGB}{249,245,233}

\newtcolorbox{myquote}{%
enhanced, breakable,
size=fbox,
frame hidden, boxrule=0pt,
sharp corners,
colback=backquote,
borderline horizontal={.5pt}{0pt}{linequote},
borderline horizontal={.5pt}{1pt}{linequote}
}

%% Important!!
%% Use ! before "O{}" with xparse 2018-05-12
%% See: https://tex.stackexchange.com/q/434928/1952
\NewTCBListing{mycode}{ !O{} }{%
enhanced, breakable,
size=fbox,
frame hidden, boxrule=0pt,
sharp corners,
colback=gray!30,
listing only,
listing options={%
style=tcblatex,
keywordstyle=\color{brown!70!black},
texcsstyle=*\color{brown!70!black}
},
#1}

\listfiles
\begin{document}
\lipsum[1]

\begin{myquote}
\lipsum[2]
\end{myquote}

\begin{mycode}
\documentclass{article}
\begin{document}
Hello
\end{document}
\end{mycode}

\end{document}


Update A minimal default version with an optional parameter to change anything.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\definecolor{linequote}{RGB}{224,215,188}
\definecolor{backquote}{RGB}{249,245,233}

\newtcolorbox{myquote}[1][]{%
enhanced, breakable,
size=minimal,
frame hidden, boxrule=0pt,
sharp corners,
colback=backquote,
#1
}

\begin{document}
\lipsum[2]

\begin{myquote}
\lipsum[2]
\end{myquote}

\begin{myquote}[colback=red!30, size=small]
\lipsum[2]
\end{myquote}

\end{document}


• (Repeating the comment I wrote to egreg.) Thanks! Even though I used this site's quotation look as a convenient example, it is far fancier than I need. In particular, the top and bottom rules for the quotation box are unnecessary. IMO, this answer would be greatly improved if the solution were simplified as much as possible, by removing the top and bottom rules. IOW, the difference between the quoted and unquoted text could be as minimal as only a change in the background color. – kjo Jun 13 '18 at 15:03
• @kjo I've updated a more minimal version, no top and bottom lines, no space around the paragraph, just background color. Although you can change the default design with the optional parameter. And once the box is defined, it's use is like a regular quotation environment. – Ignasi Jun 13 '18 at 16:28