# Simplest way to get a colored rectangle behind text? [duplicate]

I'd like to display a grey rectangle behind text, so that certain parts of the text are more recognisable. I will do this to highlight problems' body.

I found various packages, like fancytooltips or tcolorbox but I feel they're too complicated for what I'm trying to achieve.

Ideally it would be a simple grey rectangle, just like what you get when you add a quote on Math.SE:

The special left border isn't even necessary. What's the simplest way to achieve this?

A solution with the shaded environment of the package framed:

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{framed}

\begin{document}
Wikipedia claims
\noindent The fundamental theorem of a field of mathematics is the theorem considered central to that field. The naming of such a theorem is not necessarily based on how often it is used or the difficulty of its proofs.
So I am left wondering: what \emph{is} the main criterion for a theorem to be considered fundamental?
\end{document}


Another example with a theorem environment inside:

\documentclass{article}
\usepackage{amsthm}
\usepackage[svgnames]{xcolor}
\usepackage{framed}

\theoremstyle{definition}
\newtheorem{mythm}{Theorem}

\begin{document}
Wikipedia claims
\begin{mythm}
The fundamental theorem of a field of mathematics is the theorem considered central to that field. The naming of such a theorem is not necessarily based on how often it is used or the difficulty of its proofs.
\end{mythm}
So I am left wondering: what \emph{is} the main criterion for a theorem to be considered fundamental?
\end{document}


• This framed package is awesome. I think I'll be doing something along the lines of \definecolor{shadecolor}{gray}{0.9}. I especially like the fact that the box exceeds the lateral margins a bit. – rubik Feb 24 '15 at 14:16
• I got the following error: Package xcolor Error: Undefined color LightGray'. – AgilePro May 18 '17 at 14:28

Same as David's but more elaborate and with a picture ;-)

\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\newcommand{\highlight}[1]{%
\par\noindent
\colorbox{gray!30}{%
\parbox{\dimexpr\linewidth-2\fboxsep\relax}{%
#1
}%
}}

\begin{document}
\lipsum[1]
\highlight{\lipsum*[1]}
\end{document}


But I don't agree with you in that tcolorbox is complicated. See the following for example.

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\newtcolorbox{mybox}{colback=gray!30,
boxrule=0pt,arc=0pt,boxsep=2pt,left=2pt,right=2pt,leftrule=1pt}

\begin{document}
\lipsum[1]
\begin{mybox}
\lipsum*[1]
\end{mybox}
\end{document}


• Yeah, you're right, tcolorbox is not that complicated, now that I see your proposal. – rubik Feb 24 '15 at 14:14

color package and

\colorbox[gray]{0.5}{\parbox{.7\textwidth}{The fundamental......}}
`