What is the simplest, most canonical way to change the background color of quoted text?
A simple code based on framed
and quoting
which can break across pages:
\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{framed}
\usepackage{quoting}
\colorlet{shadecolor}{LavenderBlush2}
\usepackage{lipsum}
\newenvironment{shadedquotation}
{\begin{shaded*}
\quoting[leftmargin=0pt, vskip=0pt]
}
{\endquoting
\end{shaded*}
}
\begin{document}
\lipsum*[1-4]
\begin{shadedquotation}
\lipsum*[5-6]
\end{shadedquotation}
\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}
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}