How to highlight important parts (with a gray background)
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}
\theoremheaderfont{\bfseries}
\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}
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}