为什么我的 Tikz 无法在独立文档类中显示颜色?但文章类中可以显示颜色

为什么我的 Tikz 无法在独立文档类中显示颜色?但文章类中可以显示颜色

为什么我的 Tikz 无法在独立文档类中显示颜色?但是颜色可以在文章类中显示。

这是我遵循的代码例如:生锈的铁

    % 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}

结果是这样的:

带颜色的文章类别

但是如果我将该类改为独立类,代码如下:

    % 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}

结果是这样的,没有任何颜色:

无颜色的独立类

那么我该如何调整它以在独立类中显示颜色?

因为我需要将图片作为独立图片插入到我的latex文档中,以便稍后上传图片。

答案1

我知道问题所在。如果我使用,XeLaTeX我无法获得该颜色,但如果我将其更改XeLaTeX为该PDFLaTeX 颜色,则颜色会恢复原样,尽管我不知道原因。

但这可以解决问题。PDFLaTeX

相关内容