130

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 ?

1 Answer 1

147

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}
6
  • 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. Nov 17, 2012 at 16:21
  • 1
    @MaltheEisum did you find a solution for this problem of the color reaching over the borders? Jun 29, 2020 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. Nov 4, 2020 at 19:01
  • 1
    how can I see what packages are adding xcolor? how was pgfplots identified in this case? thanks! Jun 8, 2021 at 17:54
  • 1
    Do you get an answer but I wanna know as well@BogdanMihai
    – jxhyc
    Dec 5, 2021 at 8:34

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.