1

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
% Author: Jason Waskiewicz
% 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,
        iron/.style={shade, ball color=red},
        electron/.style={shade, ball color=green},
        oxygen/.style={shade, ball color=blue},
        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:

article class with color

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

    % Rusting Iron
% Author: Jason Waskiewicz
% 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,
        iron/.style={shade, ball color=red},
        electron/.style={shade, ball color=green},
        oxygen/.style={shade, ball color=blue},
        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:

standalone class without 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.

sikisis
  • 225
  • I ran your code and it worked fine – Very23 Sep 22 '15 at 03: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 03: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 03:31
  • 1
    @Very23 I solve it simply change XeLaTeX into PDFLaTeX – sikisis Sep 22 '15 at 03:40
  • Im using TeXstudio with TeX Live 2015 and I change the document class into standalone and worked fine – Very23 Sep 22 '15 at 03:41
  • @Very23 yeah, Thank you for your suggestion and I realize that I am using XeLaTeX default for Gummi but maybe PDFLaTeX can do better. – sikisis Sep 22 '15 at 03:43

1 Answers1

0

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.PDFLaTeX

sikisis
  • 225
  • No, This works with xelatex too. May be you need to update your tex distribution. –  Sep 22 '15 at 05:28
  • It is perhaps this problem (which has been solved) http://tex.stackexchange.com/questions/151524/tikz-3-0-0-release-produces-strange-shadings-if-used-with-xelatex-and-standalo – Ulrike Fischer Sep 22 '15 at 08: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 00:55
  • @HarishKumar yeah, maybe I should update – sikisis Sep 23 '15 at 00:55