# Enumerated text and formula with background color

I want to have an enumeration with text and formulas with a background color, but \colorbox does not work, here's my code:

\documentclass{book}
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{wrapfig}
\usepackage{amssymb}
\usepackage{graphicx}

\definecolor{usethiscolorhere}{rgb}{0.86666,0.78431,0.78431}

\begin{document}
%\colorbox{usethiscolorhere}{
\begin{enumerate}
\item bla bla
\item bla bla
\item \begin{aligned}[t]\lim _{x \rightarrow -\infty}F(x)=0 \end{aligned} and \begin{aligned}[t]lim_{x \rightarrow \infty} F(x)=1\end{aligned}
\end{enumerate}
%}
\end{document}


The color should be one of my self defined colors.

-

You need to avoid the indentation and also to take into account the padding of \colorbox:

\documentclass{book}
\usepackage{xcolor}
\usepackage{amsmath}

\definecolor{usethiscolorhere}{rgb}{0.86666,0.78431,0.78431}

\begin{document}
\noindent\colorbox{usethiscolorhere}{%
\begin{minipage}{\dimexpr\textwidth-2\fboxsep}
\begin{enumerate}
\item bla bla
\item bla bla
\item $\lim\limits_{x\to -\infty}F(x)=0$ and
$\lim\limits_{x\to\infty} F(x)=1$
\end{enumerate}
\end{minipage}%
}
\end{document}


Note the two % characters for avoiding spurious spaces in the output and \limits to get the subscript underneath "lim".

-

Another approach can be the hf-tikz package (two compilation runs are necessary).

Here are some examples:

\documentclass{book}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage[customcolors]{hf-tikz}

\definecolor{usethiscolorhere}{rgb}{0.86666,0.78431,0.78431}
\hfsetfillcolor{usethiscolorhere}

\begin{document}
First possibility:
\begin{enumerate}
\item bla bla
\item bla bla
\item \tikzmarkin{first}(0.05,-0.3)(-0.05,0.4)\begin{aligned}[t]\lim _{x \rightarrow -\infty}F(x)=0 \end{aligned}\tikzmarkend{first} and \tikzmarkin{second}(0.05,-0.3)(-0.05,0.4)\begin{aligned}[t]\lim_{x \rightarrow \infty} F(x)=1\end{aligned}\tikzmarkend{second}
\end{enumerate}

Second possibilty:
\begin{enumerate}
\item \tikzmarkin{enumerate}(0.05,-0.3)(-0.05,0.4)bla bla
\item bla bla
\item \begin{aligned}[t]\lim _{x \rightarrow -\infty}F(x)=0 \end{aligned} and \begin{aligned}[t]lim_{x \rightarrow \infty} F(x)=1\end{aligned}\tikzmarkend{enumerate}
\end{enumerate}

Third possibility:

\tikzmarkin{whole enumerate}(0.05,-0.4)(-0.3,0)
\begin{enumerate}
\item bla bla
\item bla bla
\item \begin{aligned}[t]\lim _{x \rightarrow -\infty}F(x)=0 \end{aligned} and \begin{aligned}[t]lim_{x \rightarrow \infty} F(x)=1\end{aligned}\tikzmarkend{whole enumerate}
\end{enumerate}

\end{document}


-
mh, wait one more problem: I compiled it twice and I get the error message: ! LaTeX Error: File hf-tikz.sty' not found. –  Germnaon Aug 28 '12 at 15:57
This is probably due to the fact that the package is quite recent: I think you should update your distribution. –  Claudio Fiandrino Aug 28 '12 at 15:58
could you tell me how to get that edge into the solution cmhuges told me? With the mdframed stuff? Thanks! –  Germnaon Aug 28 '12 at 15:59
Do you mean the rounded corners? –  Claudio Fiandrino Aug 28 '12 at 16:02
also yes, both, the pink color and the round corners –  Germnaon Aug 28 '12 at 16:02

The reason the \colorbox command isn't working is that it expects to work on a box; the enumerate environment is not in a box, so you can fix it by either using (for example) a vbox or a minipage

\documentclass{book}
\usepackage{xcolor}
\usepackage{amsmath}

\definecolor{usethiscolorhere}{rgb}{0.86666,0.78431,0.78431}

\begin{document}
\colorbox{usethiscolorhere}{
\vbox{
\begin{enumerate}
\item bla bla
\item bla bla
\item \begin{aligned}[t]\lim _{x \rightarrow -\infty}F(x)=0 \end{aligned} and \begin{aligned}[t]lim_{x \rightarrow \infty} F(x)=1\end{aligned}
\end{enumerate}
}
}
\end{document}


• I noticed you were loading the shadethm package. I'm not sure what the 'official' recommendation is, but personally I consider this package obsolete in favour of the significantly more powerful mdframed package. The shadethm has lots of limitations that mdframed does not
• Rather than using a colorbox for this kind of colouring, I would use the mdframed to define an environment for it- a complete MWE follows for your reference

mdframed example

\documentclass{book}
\usepackage{mdframed}
\usepackage{amsmath}

\definecolor{usethiscolorhere}{rgb}{0.86666,0.78431,0.78431}

\newmdenv[backgroundcolor=usethiscolorhere]{myframedenv}

\begin{document}

\begin{myframedenv}
\begin{enumerate}
\item bla bla
\item bla bla
\item \begin{aligned}[t]\lim _{x \rightarrow -\infty}F(x)=0 \end{aligned} and \begin{aligned}[t]lim_{x \rightarrow \infty} F(x)=1\end{aligned}
\end{enumerate}
\end{myframedenv}
\end{document}


If you want rounded corners, then you can use something like

\usepackage[framemethod=tikz]{mdframed}
\definecolor{usethiscolorhere}{rgb}{0.86666,0.78431,0.78431}

\newmdenv[backgroundcolor=usethiscolorhere,
roundcorner=10pt,
linecolor=blue,
]{myframedenv}


which gives

-
thanks a lot! Nice work! –  Germnaon Aug 28 '12 at 15:28
@Germnaon you're welcome :) if the answer has helped, please remember to upvote it using the up arrow. If it has resolved the problem, please consider accepting the answer using the green check mark –  cmhughes Aug 28 '12 at 15:31
ok, well I like the third possibilty more, but then I get the error message: ! LaTeX Error: File hf-tikz.sty' not found. or could you tell me, how can I get this colored edge into my myframedenv? Thanks! –  Germnaon Aug 28 '12 at 15:58
@Germnaon I think you posted on the wrong answer –  cmhughes Aug 28 '12 at 16:06
ok, I got \newmdenv[backgroundcolor=thiscolorhere,linecolor=blue]{myframedenv} but how can I get those round edges/corners ? –  Germnaon Aug 28 '12 at 16:12