LaTeX forum ⇒ Text FormattingBackground color in enumerate environment

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

Background color in enumerate environment

Postby eureka » Thu Jun 02, 2011 12:42 pm

Hi,

My purpose is to have my items in a blue background color.
I tried to use
  1. ...
  2. \usepackage[usenames,dvipsnames]{color}
  3. ...
  4. \colorbox{blue}
  5. {
  6. \being{enumerate}
  7. \item Hello
  8. \item world!
  9. \end{enumerate}
  10. },

but I got the error message:
  1. ! 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.

User avatar
Stefan Kottwitz
Site Admin
Posts: 9406
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Thu Jun 02, 2011 1:45 pm

Hi Eureka,

welcome to the board!

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

  1. \colorbox{blue}{%
  2. \parbox{.5\linewidth}{%
  3. \begin{enumerate}
  4. \item Hello
  5. \item world!
  6. \end{enumerate}%
  7. }%
  8. }


Stefan
Site admin

eureka
Posts: 2
Joined: Thu Jun 02, 2011 10:27 am

Postby eureka » Thu Jun 02, 2011 2:17 pm

Perfect, thanks Stefan!

praveen25488
Posts: 3
Joined: Mon Sep 25, 2017 7:35 am

Postby praveen25488 » Wed Mar 27, 2019 11:20 am

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: 9406
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Thu Mar 28, 2019 4:40 pm

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
Site admin


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 3 guests