9

I am trying to add a tcolorbox into my Xelatex document but it does not seem to work. I tracked the problem to the color package which if disabled produces the box. However I need to use the color package.

How can I work around this?

Here is a MWE

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}

% Uncomment the next line to get the error
%\usepackage[usenames,dvipsnames]{color}

\begin{document}

\begin{tcolorbox}[colback=green!5,colframe=green!40!black,title=A nice heading]
\lipsum[2]
\end{tcolorbox}

\end{document}
3
  • 3
    Load the package before tcolorbox but load xcolor rather than color. The same options will work.
    – cfr
    Apr 13, 2015 at 2:27
  • 1
    Have you tried with the package xcolor?
    – Dox
    Apr 13, 2015 at 2:28
  • 1
    @Dox Yes. Have you? The problem is the loading order. Because the OP is passing options to the package and tcolorbox loads the package without those options, there's a clash. You need all the options to be passed at once to the package. Loading the package first works fine. xcolor is recommended but it isn't the problem.
    – cfr
    Apr 13, 2015 at 2:31

2 Answers 2

13

xcolor is an enhanced version of color but the real trick here is simply to load it first:

\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{lipsum}


\begin{document}

\begin{tcolorbox}[colback=green!5,colframe=green!40!black,title=A nice heading]
\lipsum[2]
\end{tcolorbox}

\end{document}

box back

5

tcolorbox loads pgf which loads xcolor without options. If you want to pass some options to xcolor (which completely integrates color functionality) you can use cfr solution \usepackage[]{xcolor} with specific options before loading tcolorbox, but you also have two more options.

The first one would be to use \PassOptionsToPackage{usenames,dvipsnames}{xcolor} which passes options usenames and dvipsnames whenever xcolor is loaded.

\PassOptionsToPackage{usenames,dvipsnames}{xcolor}
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}

\begin{document}

\begin{tcolorbox}[colback=JungleGreen!5, colframe=JungleGreen!40!black, title=A nice heading]
\lipsum[2]
\end{tcolorbox}

\end{document}

And a second one consists in passing these options through \documentclass because from page 17 in LaTeX Companion, 2ed:

All options to \documentclass (both declared and global ones) are automatically passed as class options to all \usepackage declarations. Thus, if a package file loaded with a \usepackage declaration recognizes (i.e. declares) some of the class options, it can take appropriate actions. If not, the class options will be ignores while processing that package.

As a simple test, I've changed green to JungleGreen (in dvipsnames list) in your example and tried with

\documentclass[dvipsnames]{article} %<--- usenames is an obsolete option. deleted.
\usepackage{tcolorbox}
\usepackage{lipsum}

\begin{document}

\begin{tcolorbox}[colback=JungleGreen!5, colframe=JungleGreen!40!black, title=A nice heading]
\lipsum[2]
\end{tcolorbox}

\end{document}

which works without problems:

enter image description here

You must log in to answer this question.

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