File `xcolor.sty' not found

I am trying to run the below code from this link:

It is suppose to give this table: However I got LaTex Error: File 'xcolor.sty' not found.
Please advise !

\rowcolors{3}{green!80!yellow!50}{green!70!yellow!40}
\begin{tabular}{ |p{3cm}|p{3cm}|p{3cm}| }
\hline
\multicolumn{3}{|c|}{Country List} \
\hline
Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \
\hline
Afghanistan & AF &AFG \
Aland Islands & AX & ALA \
Albania &AL & ALB \
Algeria &DZ & DZA \
American Samoa & AS & ASM \
Andorra & AD & AND \
Angola & AO & AGO \
\hline
\end{tabular}

xcolor is a LaTeX package. Try to install it first before using it, and then add the following in the YAML section:

header-includes:
- \usepackage{xcolor}

I hope it'll work. I haven't tested it myself, though.

I did installed MikTex but it didn’t work.
And I added that to the headers.

What did you try? Have you at all tried to modify my code based on this line from the link you shared earlier?

\usepackage[table]{xcolor}

The following works on my device with no problem. It generates try.pdf (51.8 KB).

---
title: "Untitled"
output: pdf_document
header-includes:
- \usepackage[table]{xcolor}
- \usepackage{multirow}
---

some text

\rowcolors{3}{green!80!yellow!50}{green!70!yellow!40}

\begin{tabular}{ |p{3cm}|p{3cm}|p{3cm}|  }
\hline
\multicolumn{3}{|c|}{Country List} \\
\hline
Country Name     or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \\
\hline
Afghanistan & AF &AFG \\
Aland Islands & AX   & ALA \\
Albania &AL & ALB \\
Algeria    &DZ & DZA \\
American Samoa & AS & ASM \\
Andorra & AD & AND   \\
Angola & AO & AGO \\
\hline
\end{tabular}

some text

I tried with your exact code and I get this error message:

I read here that in my MikTEX installation I am missing Latex xcolor and should install it.
I went to Latex installation and I don't see xcolor as well.
Did I install a package that is missing it ? Please advise !

As I said in your previous threads, I use tinytex. I haven't used MikTeX for long.

What I remember is that it was possible to install packages manually from the package manager (may be called MikTeX console).

There's also another option of Automatic package installation.

Try any or both of these options. But, may I ask why don't you switch to tinytex?

Yarnabrina,
Thanks for showing me how to install packages manually and automatically in MikTex console.
I uninstalled MikTex and installed tinytex and your example works.
The reason I am using MikTex is because I want to see if it works using it as well.
Just in case I needed to use MikTex and not tinytex for certain machine.

I can confirm that Yarnabrina's example also works on MikTex with "Always install packages on-the-fly" option enabled.

1 Like

@andresrcs
Thanks, how do we have "Always Install packages on the fly option enabled" ?
How about Tex Live, do you think that is good and does it work ?

You can set this option in the MikTex console

About TexLive I have never use it on windows but in Ubuntu the auto install works out of the box, as long as you have proper permissions.

Great to know. Thanks !

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