163

I'm writing a report, and have a rather large table in my appendix. I'd like to emphasize some specific values by coloring some single cells. I'm trying to do it with xcolor. But receiving the error:

! LaTeX Error: Option clash for package xcolor.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.17
The package xcolor has already been loaded with options:
[]
There has now been an attempt to load it with options
[table]

My preamble looks as follows

\documentclass[a4paper,oneside,article]{memoir}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[danish]{babel}
\usepackage{lmodern}
\usepackage{graphicx}
    \graphicspath{{Figures/}}
\usepackage{fullpage}
\usepackage{modroman}
\usepackage{float}
\usepackage{caption}
\usepackage[numbers]{natbib}
\usepackage{url}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage[table]{xcolor}

And take out of my table

\begin{table}
 \centering
  \begin{tabular}{|c|c|c|}
       \hline
   \cellcolor{green!25}D & x & D/$L_0$ \\
       \hline
   65 & 2600 & 0,417\\
       \hline
   60 & 2400 & 0,385\\
  \end{tabular}
 \caption{Bestemmelse af bølgehøjde}
 \label{tab:Q1}
\end{table}

Read some other questions asking more or less the same. And the answer to them seems to be a "collision" between packages. I have no idea how to find the problem. So my question is:

  1. Where is the "collision"?
  2. How on earth would I have found it without help ?
David Carlisle
  • 757,742
Malthe Eisum
  • 3,019

3 Answers3

185

Once you get the error message:

! LaTeX Error: Option clash for package xcolor.

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

l.17 

type "h" (without the quotation marks, for help) in the output console and you get

? h
The package xcolor has already been loaded with options:
  []
There has now been an attempt to load it with options
  [table]
Adding the global options:
  ,table
to your \documentclass declaration may fix this.

So, you get an explanation of the problem and a possible solution. Doing as advised you prevent the clash:

\documentclass[a4paper,oneside,article,table]{memoir}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[danish]{babel}
\usepackage{lmodern}
\usepackage{graphicx}
    \graphicspath{{Figures/}}
\usepackage{fullpage}
\usepackage{modroman}
\usepackage{float}
\usepackage{caption}
\usepackage[numbers]{natbib}
\usepackage{url}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{xcolor}

\begin{document}
test
\end{document}

Now, the problem was that another package (pgfplots, in this case) had already loaded the xcolor package without options, so loading it after pgfplots with the table option produces the clash. One way to prevent the problem was already presented (using table as class option); another solution is to load xcolor with the table option before pgfplots:

\documentclass[a4paper,oneside,article]{memoir}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[danish]{babel}
\usepackage{lmodern}
\usepackage{graphicx}
    \graphicspath{{Figures/}}
\usepackage{fullpage}
\usepackage{modroman}
\usepackage{float}
\usepackage{caption}
\usepackage[numbers]{natbib}
\usepackage{url}
\usepackage[table]{xcolor}
\usepackage{pgfplots}
\usepackage{mathtools}

\begin{document}
test
\end{document}
Gonzalo Medina
  • 505,128
  • Thank you, both solutions works, now i just have the problem of the borders of the table being covered by the cellcolor :), I will do some poking around. – Malthe Eisum Nov 17 '12 at 16:21
  • 1
    @MaltheEisum did you find a solution for this problem of the color reaching over the borders? – white_gecko Jun 29 '20 at 21:18
  • @white_gecko Are you sure cellcolor covers your border lines? It might also just be an issue of your PDF viewer that renders the table. You should see the lines when you zoom in. – stackprotector Nov 04 '20 at 19:01
  • I don't have the example with me at the moment, but as I recall the effect was very obvious and I can't imagine it was just a matter of the viewer. – white_gecko Nov 04 '20 at 19:24
  • 4
    how can I see what packages are adding xcolor? how was pgfplots identified in this case? thanks! – Bogdan Mihai Jun 08 '21 at 17:54
  • 1
    Do you get an answer but I wanna know as well@BogdanMihai – jxhyc Dec 05 '21 at 08:34
18

Another way is to paste this line

\PassOptionsToPackage{table}{xcolor}

before

\documentclass{...}

as was already referenced here!

1

If you used tikz related package, then one way that works for my computer is to load the xcolor before tikz. Example:

Correct:

\documentclass[]{article}

\usepackage[dvipsnames]{xcolor} \usepackage{tikz-cd}% xcolor first

\begin{document} {\color{SkyBlue} This is a test.} \end{document}

Wrong:

\documentclass[]{article}

\usepackage{tikz-cd}% xcolor should be first \usepackage[dvipsnames]{xcolor}

\begin{document} {\color{SkyBlue} This is a test.} \end{document}

Asigan
  • 135