[Tex/LaTex] Change color and background behind text of all ‘description’ environments

colorenvironments

I'm new with LaTeX and like to change some parameters of the description environment throughout the document.
As minimum, I like to have two arguments: color of text of item and background-color behind text as description.

In other words, I want to give style.

Best Answer

Unfortunately you can not change the style of environments as easy as it is possible using CSS with HTML. However, you can redefine description or define your own variant which adds the color commands.

To set the background color you can use my adjustbox package:

\documentclass{article}
\usepackage{xcolor}
\usepackage{adjustbox}

\newenvironment{cdescription}{%
  \begin{adjustbox}{minipage=\linewidth,bgcolor=blue,vspace=\smallskipamount}
    \begin{description}
      \color{red}%
}{%
    \end{description}
  \end{adjustbox}
}

\begin{document}

Text before

\begin{cdescription}
    \item[Hello] World
    \item[Example] Item
\end{cdescription}

text after

\end{document}

If you want to redefine description instead you can save the old definition away and use it internally.

\let\olddescription\description
\let\endolddescription\enddescription
\renewenvironment{description}{%
  \begin{adjustbox}{minipage=\linewidth,bgcolor=blue,vspace=\smallskipamount}
    \begin{olddescription}
      \color{red}%
}{%
    \end{olddescription}
  \end{adjustbox}
}

If you want to set the colors for every environment simply add [2] after the environment name (e.g., \newenvironment{cdescription}[2]{%) and replace the color names with #1 and #2 in the definition.