# How to highlight important parts (with a gray background)

http://www.math.uiowa.edu/~goodman/algebrabook.dir/bookmt.pdf

the author highlights anything which is important using a greyish color background. For example, if you see Equation 1.5.3 (which on page 22 of the book) it is highlighted in grey. I would like to know the TeX commands for producing similar output.

-
check out the mdframed package. –  Harish Kumar Mar 5 '12 at 3:53
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  Tobi Mar 5 '12 at 4:03
In addition to Harish’s comment I recommend to define commands and environments for those thing you want to highlight. So all of them look the same but can be change easily afterword if necessary. After checking mdframed you may post a minimal working example (MWE) to show, what you’ve tried so far … –  Tobi Mar 5 '12 at 4:06

As mentioned in the comments, mdframed is perfect for this. You can combine it with your favourite theorem package too- in the MWE below I've used it with ntheorem, but there's nothing to stop you from using amsthm or something similar.

This example is very simple, but you can get very sophisticated using tikz or pstricks as the engine, as shown in the excellent documentation

\documentclass{article}

\usepackage{xcolor}     % for colour
\usepackage{lipsum}     % for sample text
\usepackage{ntheorem}   % for theorem-like environments
\usepackage{mdframed}   % for framing

\theoremstyle{break}
\newmdtheoremenv[%
linecolor=gray,leftmargin=60,%
rightmargin=40,
backgroundcolor=gray!40,%
innertopmargin=0pt,%
ntheorem]{myprop}{Proposition}[section]

\begin{document}

\section{mdframed for the win}
\begin{myprop}
\lipsum[1]
\end{myprop}

\end{document}

-
This is not working for me due to some reason. I am not getting the output. –  chandrasekhar Mar 5 '12 at 8:30
@chandrasekhar add \listfiles immediately before your \begin{document}- it sounds like your system needs to be updated –  cmhughes Mar 5 '12 at 16:57

With tcolorbox:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{kantlipsum}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[breakable, theorems, skins]{tcolorbox}
\tcbset{enhanced}

\DeclareRobustCommand{\mybox}[2][gray!20]{%
\begin{tcolorbox}[   %% Adjust the following parameters at will.
breakable,
left=0pt,
right=0pt,
top=0pt,
bottom=0pt,
colback=#1,
colframe=#1,
width=\dimexpr\textwidth\relax,
enlarge left by=0mm,
boxsep=5pt,
arc=0pt,outer arc=0pt,
]
#2
\end{tcolorbox}
}

\begin{document}
\mybox[green!20]{\kant[1]}
\mybox{\kant[2]}
\mybox[red!20!white]{\kant}

\end{document}


tcolorbox integrates flawlessly with theorem packages and math. Further, it can produce more fancier boxes than one can imagine. I feel that this is the best option to adopt when one has to highlight text / math / theorems. Though I have defined a command, new environments can also be defined with tcolorbox. For details, texdoc tcolorbox or visit www.texdoc.net.

A sample preposition:

\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbuselibrary{theorems}
\usepackage{kantlipsum}

\newtcbtheorem{Proposition}{Proposition}%
{breakable,colframe=red!50!white!50!black,fonttitle=\bfseries}{}

\begin{document}
\begin{Proposition}{This is my proposition}{}
\kant
\end{Proposition}
\end{document}


# Earlier attempt:

Sorry for joining late. I would like to add to cmhughes's excellent answer. Though his reply is already accepted as the answer, I wish to share mine. My method is simple and direct where colors can be changed very easily.

\documentclass[11pt]{article}
\usepackage{xcolor}
\usepackage{lipsum}
\newcommand*{\mybox}[2]{\colorbox{#1!30}{\parbox{.98\linewidth}{#2}}}
\begin{document}
%=====================
\section{First section}
%=====================
\mybox{green}{\lipsum[1]}
\par
\noindent\mybox{red}{\lipsum[2]}
\end{document}


-
this won't break across pages though... –  cmhughes Mar 5 '12 at 16:58
@cmhughes Correct. But the file provided above by the OP does not require breaking across pages. It is for just highlighting small bits of text (like a line or two. I also go with mdframed for things like these. (as I commented above) My answer is added just for fun. –  Harish Kumar Mar 5 '12 at 22:52
@HarishKumar:Very nice way of doing it! –  Thanos Oct 7 '12 at 11:56