10

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{shadethm}
\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.

Germnaon
  • 109

3 Answers3

7

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".

enter image description here

egreg
  • 1,121,712
5

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

enter image description here

\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}

Comments

  • 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}

enter image description here

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

enter image description here

cmhughes
  • 100,947
5

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}

enter image description here