# Why my Tikz can not show color in standalone document class ? But the color do show in article class

Why my Tikz can not show color in standalone document class ? But the color do show in article class.

Here is the code which I follow from Example: Rusting Iron

    % Rusting Iron
% A "jazzy" picture of the stages of rust (presented for a high school level).
% Iron is red, oxygen is blue and electrons are black. At the left you see
% iron atoms with two oxygen molecules, then the electrons go to the oxygen molecules
% leaving oxygen ions and iron ions which then disolve.
\documentclass{article}

\usepackage[usenames,dvipsnames]{xcolor}

\usepackage{standalone}
% Load all packages needed for all sub−files:
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[
>=stealth,
droplet/.style={ball color=blue!20, opacity=0.4},
]

\begin{scope} % Energy levels
\draw (0,0) node[left] {$y=0$} --
++(10.8,0) ;%node[right] {$0,108$}
\draw (0,1.6) node[left] {$y=16$} --
++(10.8,0) ; %node[right] {$16,108$}
\end{scope}

\foreach \x in {0.200000, 0.500000, 0.800000, 1.100000, 2.900000, 3.200000, 3.500000, 3.800000, 5.600000, 5.900000, 6.200000, 6.500000, 8.300000, 8.600000, 8.900000, 9.200000}
\draw [iron] (\x,0,0) circle (0.2cm);

\foreach \x in {1.400000, 4.100000, 6.800000, 9.500000}
\draw [electron] (\x,0,0) circle (0.2cm);

\foreach \x in {1.700000, 2.000000, 2.300000, 2.600000, 4.400000, 4.700000, 5.000000, 5.300000, 7.100000, 7.400000, 7.700000, 8.000000, 9.800000, 10.100000, 10.400000, 10.700000}
\draw [oxygen] (\x,0,0) circle (0.2cm);

\end{tikzpicture}

\end{document}


The result is like this:

But if I change the class into standalone ,the code is below:

    % Rusting Iron
% A "jazzy" picture of the stages of rust (presented for a high school level).
% Iron is red, oxygen is blue and electrons are black. At the left you see
% iron atoms with two oxygen molecules, then the electrons go to the oxygen molecules
% leaving oxygen ions and iron ions which then disolve.
\documentclass{standalone}

\usepackage[usenames,dvipsnames]{xcolor}

% Load all packages needed for all sub−files:
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[
>=stealth,
droplet/.style={ball color=blue!20, opacity=0.4},
]

\begin{scope} % Energy levels
\draw (0,0) node[left] {$y=0$} --
++(10.8,0) ;%node[right] {$0,108$}
\draw (0,1.6) node[left] {$y=16$} --
++(10.8,0) ; %node[right] {$16,108$}
\end{scope}

\foreach \x in {0.200000, 0.500000, 0.800000, 1.100000, 2.900000, 3.200000, 3.500000, 3.800000, 5.600000, 5.900000, 6.200000, 6.500000, 8.300000, 8.600000, 8.900000, 9.200000}
\draw [iron] (\x,0,0) circle (0.2cm);

\foreach \x in {1.400000, 4.100000, 6.800000, 9.500000}
\draw [electron] (\x,0,0) circle (0.2cm);

\foreach \x in {1.700000, 2.000000, 2.300000, 2.600000, 4.400000, 4.700000, 5.000000, 5.300000, 7.100000, 7.400000, 7.700000, 8.000000, 9.800000, 10.100000, 10.400000, 10.700000}
\draw [oxygen] (\x,0,0) circle (0.2cm);

\end{tikzpicture}

\end{document}


the result is like this,without any color:

So how can I adjust this to show the color in standalone class?

Because I need to insert the picture as a standalone picture into my latex document for uploading pictures later.

• I ran your code and it worked fine – Very23 Sep 22 '15 at 3:24
• @Very23 Could you tell me you compiler and version of latex? I am using XeTeX, Version 3.14159265-2.6-0.99991 (TeX Live 2014) (preloaded format=xelatex) – sikisis Sep 22 '15 at 3:30
• @Very23 yeah My code is right but if you change article into standalone the color is missing. I edited my question to further specify the details. – sikisis Sep 22 '15 at 3:31
• @Very23 I solve it simply change XeLaTeX into PDFLaTeX – sikisis Sep 22 '15 at 3:40
• Im using TeXstudio with TeX Live 2015 and I change the document class into standalone and worked fine – Very23 Sep 22 '15 at 3:41

I know the problem. If I use XeLaTeX I can not get the color but if I change XeLaTeX into PDFLaTeX　the color is back althought I do not know why.

But That works to solve the problem.

• No, This works with xelatex too. May be you need to update your tex distribution. – user11232 Sep 22 '15 at 5:28
• It is perhaps this problem (which has been solved) tex.stackexchange.com/questions/151524/… – Ulrike Fischer Sep 22 '15 at 8:35
• @UlrikeFischer Thank you! That's it. I also can reproduce the problem in the post you mention. Maybe I should follow the suggestion. – sikisis Sep 23 '15 at 0:55
• @HarishKumar yeah, maybe I should update – sikisis Sep 23 '15 at 0:55