# How to Create Colored Text Boxes with DIFFERENT colors using “\leftbar” command?

I am using the following code to generate a Colored Box in Latex:

\renewenvironment{leftbar}[1][\hsize]%
{%
\def\FrameCommand%
{%
\fboxsep=\FrameSep\colorbox{Lavender!25}%
}%
}%
{\endMakeFramed}

\leftbar
\textbf<\textbf{Data Type}> <\textbf{Array Name}> \textbf{[RowSize]  [ColumnSize]};
\endleftbar


The Settings for the colored box are fixed before: "\begin{document}".

Everytime, I draw a box using "\leftbar" "\endleftbar" -- it is always of the same color I mentioned in the Settings above.

But I want to get Boxes with Different Colors (Rest of the settings same as above).

It seems that "\leftbar" don't take the "color" as an Argument.

Can anybody please guide me on how to generate boxes with Different colors using "\leftbar"?

-
If you are interested in typesetting code, the listings package could be of interest for you. –  Gonzalo Medina Aug 14 '12 at 12:04
Thanks, I will explore it ! –  Sandeep Singh Aug 14 '12 at 12:11

You can use an argument for the color in the (re)definition of leftbar:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{framed}

\renewenvironment{leftbar}[2][\hsize]%
{%
\def\FrameCommand%
{%
\fboxsep=\FrameSep\colorbox{#2}%
}%
}%
{\endMakeFramed}

\begin{document}

\begin{leftbar}{green!25}
\textbf<\textbf{Data Type}> <\textbf{Array Name}> \textbf{[RowSize]  [ColumnSize]};
\end{leftbar}

\begin{leftbar}{red!25}
\textbf<\textbf{Data Type}> <\textbf{Array Name}> \textbf{[RowSize]  [ColumnSize]};
\end{leftbar}

\begin{leftbar}{olive!25}
\textbf<\textbf{Data Type}> <\textbf{Array Name}> \textbf{[RowSize]  [ColumnSize]};
\end{leftbar}

\end{document}


-
Thanks a lot, this is perfectly what I wanted ! –  Sandeep Singh Aug 14 '12 at 12:03