4

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}
1
  • @Qrrbrbirlbel Thanks, can you post that as an answer? Totally missed that tikz gets already loaded before.
    – Lennart
    Aug 11 at 11:38

1 Answer 1

4

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}

in your preamble.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.