Colors by names using xcolor, LaTeX Error: Option clash for package xcolor.

For some reason, I am not able to knit a very simple Rmd file if I use \usepackage[x11names]{xcolor}.
It pops up the message "LaTeX Error: Option clash for package xcolor".
All LaTeX functions works properly. Except this one.
I can work without options, but the color palette is so minimal, that the feeling of documents are very basic. Or I can work with a lot of code to define colors, but I need to work, not to code.
The next code is the minimum expression of my problem. A simple thing like try to change a font color is a nightmare.
The Azure1 color (at the bottom of the code) belongs to the color namespace x11names in xcolor.
If I change it to something basic like gray it will work ONLY if I delete the [option] part in xcolor package.

I am not expert at all. The answer may be too easy, but not for me.
I really need some solution.

I've had tried using \PassOptionsToPackage{x11names}{xcolor}: Same problem
I did reinstall FULL tinytext,

tinytex::reinstall_tinytex(): Same problem

I did reinstall TeX Live in my Linux.: Same problem (...and a lot of time and resources)
I did reinstall (afterwards) kableExtra, Knitr, Rmarkdown... and nothing seems to work.

Here is my Rmd example (just the problem)

always_allow_html: true
knitr::opts_chunk$set(echo = FALSE, warning=FALSE, error=FALSE)
 ```{r librerias, include = FALSE}  
 **\fontsize{28}{28}\selectfont Changing size works.**\newline
 \fontsize{20}{20}\selectfont Up or \fontsize{8}{8}\selectfont down.\newline
 The next text will have a color change **\textcolor{blue}{LIKE THIS}**, or like **\textcolor{purple}{THIS}** and finally as **\textcolor{red}{THIS ONE}** ...something else.\newline
 A very simple table
 \LARGE Sampling

 ```{r }
 tracing <- data.table(X=c(1:10), Y=c(LETTERS[1:10]))
 kable(tracing, "latex") %>%
    position = "center",
     font_size = 8,
     full_width = FALSE,
     repeat_header_continued = FALSE,
     latex_options = "striped",
     stripe_color = "Azure1"
   ) ```

I am woking over RStudio-server.
I am on your hands.
Thank you so much for your time to solve such a problem to me.


> version
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
major          4                           
minor          0.2                         
year           2020                        
month          06                          
day            22                          
svn rev        78730                       
language       R                           
version.string R version 4.0.2 (2020-06-22)
nickname       Taking Off Again 

Rstudio version:

[1] "server"

[1] ‘1.3.1073’

[1] "Giant Goldenrod"

If I use this code, I can verify some things.

The next text will have a color change **\textcolor[rgb]{0,.7,.3}{LIKE THIS}**, 
or like **\textcolor{Azure1}{THIS}** 
and finally as **\textcolor{red}{THIS ONE}** ...something else.\newline

The xcolor package is OK. I can use the [rgb] option in the \textcolor, without problem, but it is not possible to use the Azure1, whose definition is inside x11names. I can not use either another name space declared on the options given to xcolor in the header, it is not something specific to x11names.

This should work. You need to use that because pandoc latex template already use xcolor.

In this minimal reprex it does.

   - \PassOptionsToPackage{x11names}{xcolor} 
The next text will have a color change **\textcolor{blue}{LIKE THIS}**, or like **\textcolor{purple}{THIS}** and finally as **\textcolor{red}{THIS ONE}** ...something else.

Thank You Christophe...
Your work has been considered around this problem.
Your suggestion should work, but it don't.
In this code it works, because the colors in this particular fragment are the basic ones, but if I try with Azure1, or any other color in the x11names space, it displays:

output file:

! Package xcolor Error: Undefined color `Azure1'.

I have had added new code at the end of the original post. It has r.g.b. definition (OK) and the color Azure1 (!Ok)

Ok I see. This is currently something that pandoc does not handle because it loads xcolor with no option before the preamble, that is why it does not work.



So there would need to be a change in pandoc default template so that it can works smoothly with Rmardown.

Currently, I see two workaround.

It seems you can define this is as a document class option. This seems to work

     keep_tex: true
classoption: x11names
The next text will have a color change **\textcolor[rgb]{0,.7,.3}{LIKE THIS}**, 
or like **\textcolor{Azure1}{THIS}** 
and finally as **\textcolor{red}{THIS ONE}** ...something else.\newline

Or you can take advantage of the fact that pandoc template includes x11names for xcolor, if colorlinks is activated:
That means you can define the color to use in the preamble, and use it

     keep_tex: true
colorlinks: true
  - \definecolors{Azure1}
The next text will have a color change **\textcolor[rgb]{0,.7,.3}{LIKE THIS}**, 
or like **\textcolor{Azure1}{THIS}** 
and finally as **\textcolor{red}{THIS ONE}** ...something else.\newline

You can give a :+1: in pandoc issues so that they solve this maybe...

1 Like


You will never ever can imagine how much work have you saved.

This issue is all round the web... and such a solution is the simplest one. I have learned a lot during the last 4 days... but nothing worked. This is the fast way.

There are programmers, who work on programming. But there are some people like me, that use the programming as a tool, not as our job. Some of us need this approach.

Thank you so much.


I found that on the web, and it will create in your tex file this line


I don't really know enough Latex to understand why it works, but I imagine this works as global option for the packages loaded after. Mind the potential conflict!

I am glad it work for you now!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.