Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

\renewenvironment{leftbar}[1][\hsize]%
{%
        \def\FrameCommand%
        {%                  
             \fboxsep=\FrameSep\colorbox{Lavender!25}%
        }%
        \MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}%
}%
{\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"?

share|improve this question
1  
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

1 Answer 1

up vote 6 down vote accepted

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}%
        }%
        \MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}%
}%
{\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}

enter image description here

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.