162

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 ?

3 Answers 3

183

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
  • 4
    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
15

Another way is to paste this line

\PassOptionsToPackage{table}{xcolor}

before

\documentclass{...}

as was already referenced here!

1
  • You're a True Hero!
    – Leon
    Dec 2, 2022 at 11:52
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}
3
  • This not only works on your computer, it is the suggested way to do this. Nov 28, 2023 at 12:56
  • I thought this is an alternative way to say this is only a possible solution. If it is not a suitable expression, then I will edit.
    – Asigan
    Nov 28, 2023 at 15:27
  • No, I think it's fine. =) Nov 28, 2023 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .