# LaTeX Error: Option clash for package xcolor, even If I put listings before

    \usepackage{amsmath}
\usepackage{array}
\usepackage{booktabs}
\usepackage[draft]{pgf}
\usepackage{listings}
\usepackage[usenames,dvipsnames]{xcolor}


I want to use a color called 'Bittersweet' but I get this error

-

Package listings does not load xcolor, but package pgf does. In LaTeX you can load a package many times, but the option list of each package loading must be a subset of the options given at the first loading (exception is package fontenc).

The problem is solved, if the first package loading contains all options:

\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[draft]{pgf}
\usepackage{listings}


## \PassOptionsToPackage

However somtimes packages might be loaded in the document class already, or there are constraints in the package order that prevents the reordering of the packages. Then \PassOptionsToPackage helps. It can even be loaded before \documentclass. It gives the specified options to the package without loading the package:

\PassOptionsToPackage{usenames,dvipsnames}{xcolor}
...
\usepackage[draft]{pgf}
% pgf can now load the package xcolor and loads it with
% options "usenames,dvipsnames".
\usepackage{listings}
\usepackage{xcolor}
% or \usepackage[usenames,dvipsnames]{xcolor}


## Global options

BTW, the help text of the error message (press h at the interactive prompt or check the .log file) for the option clash shows the options that need to be specified at the first loading of the package.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
...

l.5 \begin
{document}

With packages like xcolor, hyperref etc. that are often loaded by other packages and classes, I definitely vote for \PassOptionsToPackage before \documentclass, it saves lots of troubles. –  yo' Feb 20 '13 at 9:30