10

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.

18

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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