Text FormattingBackground color in enumerate environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
eureka
Posts: 2
Joined: Thu Jun 02, 2011 10:27 am

Background color in enumerate environment

Post by eureka »

Hi,

My purpose is to have my items in a blue background color.
I tried to use

Code: Select all

...
\usepackage[usenames,dvipsnames]{color}
...
\colorbox{blue}
{ 
\being{enumerate} 
\item Hello 
\item world! 
\end{enumerate}
}, 
but I got the error message:

Code: Select all

! Latex error: Something's wrong -- perhaps a missing item.
What went wrong and how can I fix that?

Thanks
Last edited by eureka on Thu Jun 02, 2011 4:42 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Background color in enumerate environment

Post by Stefan Kottwitz »

Hi Eureka,

welcome to the board!

An enumerate environment inside a colorbox works if you use \parbox or a minipage environment:

Code: Select all

\colorbox{blue}{%
  \parbox{.5\linewidth}{%
    \begin{enumerate}
      \item Hello
      \item world!
    \end{enumerate}%
  }%
}
Stefan
LaTeX.org admin
eureka
Posts: 2
Joined: Thu Jun 02, 2011 10:27 am

Re: Background color in enumerate environment

Post by eureka »

Perfect, thanks Stefan!
praveen25488
Posts: 3
Joined: Mon Sep 25, 2017 7:35 am

Background color in enumerate environment

Post by praveen25488 »

What to do if We want only items like 1. 2. and so on have a background color
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Background color in enumerate environment

Post by Stefan Kottwitz »

Perhaps make two enumerate lists: the first one in a colored box such as above, and the second one started at the next number (3 etc.) . That can be done using the enumitem package.

Stefan
LaTeX.org admin
Post Reply