# How to use xcolor color names in tikzpicture style?

I want to use color names like MidnightBlue in a style for a tikzpicture to e.g. fill it with a specific color, is this possible? Or am I limited to the other style (red!30 etc.)?

This MWE fails with Package xcolor Error: Undefined color MidnightBlue.:

\documentclass[tikz]{standalone}
\PassOptionsToPackage{svgnames}{xcolor}
\usepackage{tikz}

\usetikzlibrary{positioning,fit,calc,shapes}

\begin{document}

\begin{tikzpicture}[myStyle/.style={rectangle, fill=MidnightBlue}]
\node (test) [myStyle] { Test };
\end{tikzpicture}
\end{document}

• @Qrrbrbirlbel Thanks, can you post that as an answer? Totally missed that tikz gets already loaded before. Aug 11 at 11:38

The package tikz (by way of package pgfcore) loads the xcolor package.

In your case, the standalone class with the option tikz also loads the tikz package (and configurates other settings so that it works as intended). The \usepackage{tikz} has no effect anymore.

Thus, you need to say

\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[tikz]{standalone}


or even just

\documentclass[svgnames,tikz]{standalone}


Without standalone you can just do

\documentclass{article}% or another that does not load TikZ
\usepackage[svgnames]{xcolor}
\usepackage{tikz}


or, similarly as with standalone,

\documentclass[svgnames]{article}
\usepackage{tikz}


Similar problems arise with the beamer class, however this one has a class option xcolor that can be used to forward options only to the xcolor package (xcolor=dvipsnames) – and not to all packages.