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'm trying to include some code using \usepackage{listings}. However the default look is not very pretty, so I want to customize it a bit. I've read some of the other posts about changing the layout of the code so I tried this:

    \usepackage{listings}
    \usepackage[rgb]{xcolor}
    \lstset{%
    language=C++,%
    backgroundcolor=\color{yellow!20},% sets backgroundcolor
    basicstyle=%
    \scriptsize \color{black},% basic font setting
    commentstyle=%
    \color{OliveGreen}
    }

But OliveGreen is undefined. Green is not good looking at all, so I would like to know how I can mix/create my own colors? Or maybe use another package with more standard colors in it.

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

The OliveGreen color is defined in dvipsnam.def, so you get it with

\usepackage[rgb,dvipsnames]{xcolor}

Alternatively, you can define it by stating

\definecolor{OliveGreen}{rgb}{0,0.6,0}

in your document preamble. In both cases, you can use the color by name where you wish.

With the dvipsnames option the OliveGreen color is defined in the CMYK model with what would be

\definecolor{OliveGreen}{cmyk}{0.64,0,0.95,0.40}

but the same xcolor package will convert it to the rgb specification above.

This is what I get from the following test document:

\documentclass{article}
\usepackage[rgb,dvipsnames]{xcolor}

\definecolor{OliveGreenCMYK}{cmyk}{0.64,0,0.95,0.40}
\definecolor{OliveGreenRGB}{rgb}{0,0.6,0}

\begin{document}

\colorbox{OliveGreenCMYK}{\rule{0pt}{1cm}\hspace{1cm}}\quad
\colorbox{OliveGreenRGB}{\rule{0pt}{1cm}\hspace{1cm}}\quad
\colorbox{OliveGreen}{\rule{0pt}{1cm}\hspace{1cm}}

\end{document}

which shows that the three ways of calling the color give the same result. However this can be different in the final printout, depending on the printer and the printer driver.

enter image description here

share|improve this answer
add comment

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.