6

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:

box

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

7

A solution with the shaded environment of the package framed:

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

\definecolor{shadecolor}{named}{LightGray}

\begin{document}
    Wikipedia claims
    \begin{shaded}
        \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.
    \end{shaded}
    So I am left wondering: what \emph{is} the main criterion for a theorem to be considered fundamental?
\end{document}

enter image description here

Another example with a theorem environment inside:

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

\theoremstyle{definition}
\newtheorem{mythm}{Theorem}
\definecolor{shadecolor}{named}{LightGray}

\begin{document}
    Wikipedia claims
    \begin{shaded}
        \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}
    \end{shaded}
    So I am left wondering: what \emph{is} the main criterion for a theorem to be considered fundamental?
\end{document}

enter image description here

  • 1
    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
  • 1
    I got the following error: Package xcolor Error: Undefined color LightGray'.` – AgilePro May 18 '17 at 14:28
9

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}

enter image description here

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}

enter image description here

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

color package and

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.