LaTeX forum ⇒ GeneralBackground color of an environment

LaTeX specific issues not fitting into one of the other forums of this category.
User avatar
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Background color of an environment

Postby meho_r » Fri May 09, 2008 9:30 am

Hi,

Till now, I figured out how to change color in minipage, but it isn't really what I need. It's OK for small blocks of text, but if the text is larger than a page or two, it's a problem since no text break across the pages can't be done.

To put simple: Is there a way to change background color of an environment? E.g. I have \quote environment that I want to have light grey background. How can this be achieved?

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Juanjo
Posts: 656
Joined: Sat Jan 27, 2007 12:46 am

Postby Juanjo » Fri May 09, 2008 12:03 pm

You can use the framed package. Here you have a simple example:
  1. \documentclass{article}
  2. \usepackage{framed}
  3. \usepackage{lipsum}
  4. \usepackage[dvipsnames]{color}
  5. \definecolor{shadecolor}{named}{Melon}
  6.  
  7. \begin{document}
  8.  
  9. A very long description list:
  10. \begin{shaded}
  11. \begin{description}
  12. \item[First item] \lipsum[1-3]
  13. \item[Second item] \lipsum[4-6]
  14. \item[Third item] \lipsum[9-12]
  15. \end{description}
  16. \end{shaded}
  17.  
  18. \end{document}


I copy here the head of framed.sty. To my knowledge, except that, there is no avalaible guide on the macros defined in the package:

  1. % framed.sty v 0.8a 21-Jul-2003
  2. % Copyright (C) 1992-2003 by Donald Arseneau
  3. % These macros may be freely transmitted, reproduced, or modified
  4. % provided that this notice is left intact.
  5. %
  6. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  7. % Create framed or shaded regions that can break across pages using
  8. % \begin{framed} ... \end{framed} -- ordinary frame box (box at margin)
  9. % \begin{shaded} ... \end{shaded} -- shaded background (into margin)
  10. % ... leftbar ... -- line on left side
  11. % \begin{MakeFramed}{settings} ... \end{MakeFramed}
  12. % -- generic frame (for new environments)
  13. %
  14. % The "framed" environment puts the text into "\fbox" with the
  15. % settings "\fboxrule=\FrameRule" and "\fboxsep=\FrameSep".
  16. % You can change these lengths (using "\setlength") and you
  17. % can even change the definition of "\FrameCommand" to use
  18. % much fancier boxes.
  19. %
  20. % In fact, the "shaded" environment just redefines "\FrameCommand"
  21. % to use "\colorbox{shadecolor}" (and you have to define the
  22. % color "shadecolor": \newcolor{shadecolor}...).
  23. %
  24. % A page break is allowed, and even encouraged, before the framed
  25. % environment. If you want to attach some text (a box title) to the
  26. % frame, then the text should be inserted by \FrameCommand
  27. %
  28. % The contents of the framed regions are restricted:
  29. % Floats, footnotes, marginpars and head-line entries will be lost.
  30. % (Some of these may be handled in a later version.)
  31. % This package will not work with the page breaking of multicol.sty,
  32. % or other systems that perform column-balancing.
  33. %
  34. % The MakeFramed environment does the work. Its "settings" argument
  35. % should contain any adjustments to the text width (applied to \hsize,
  36. % and using the "\width" of the frame itself) as well as a `restore'
  37. % command -- \@parboxrestore or \FrameRestore or something similar.
  38. %
  39. % Expert commands:
  40. % \MakeFramed, \endMakeFramed: the "MakeFramed" environment
  41. % \FrameCommand: command to draw the frame around its argument
  42. % \FrameRestore: restore some text settings, but fewer than \@parboxrestore
  43. % \FrameRule: length register; \fboxrule for default "framed".
  44. % \FrameSep: length register; \fboxsep for default "framed".
  45. % \FrameHeightAdjust: macro; height of frame above baseline at top of page
  46. %
  47. % This is still a `pre-production' version because I can think of many
  48. % features/improvements that should be made. Nevertheless, starting
  49. % with version 0.5 it should be bug-free.
  50. %
  51. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Postby meho_r » Fri May 09, 2008 2:12 pm

Thanks a lot, Juanjo.

I tested it with \usepackage[svgnames]{xcolor} instead of \usepackage[dvipsnames]{color} and it's working fine. This will make many things easier. Although framed is pretty limited (e.g. footnotes are lost) it can be put in good use.

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “General”

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests