TikZ 和 tikzorbital:背景问题

TikZ 和 tikzorbital:背景问题

看起来tikzorbital该软件包与基本 TikZ 库不兼容background。如下图所示,只p_y显示(不要注意 MWE 中的符号)。如果关闭背景,它会显示所有内容。

在此处输入图片描述

MWE 是...

\documentclass{article}

\usepackage[x11names]{xcolor}
\usepackage{tcolorbox} 
\usepackage[font=small]{caption}
\usepackage{float}
\usepackage{floatflt}

\usepackage{tikz} 
\usepackage{tikzorbital}
\usetikzlibrary{fadings,patterns,backgrounds,fit,arrows}

\begin{document}

\begin{figure}[ht!]\centering
  \begin{tikzpicture}[show background rectangle,background rectangle/.style={fill=LightBlue1}]
  \draw[-latex] (0,0)--(1,0) node[above]{\itshape x};
  \draw[-latex] (0,0)--(-0.5,-0.7) node[above]{\itshape y};
  \draw[-latex] (0,0)--(0,1) node[above]{\itshape z};
  \orbital[pos = {(0,0)}]{py}
  \node[above] at (0.7,0.7) {p$_x$};

  \draw[-latex] (3,0)--(4,0) node[above]{\itshape x};
  \draw[-latex] (3,0)--(2.5,-0.7) node[above]{\itshape y};
  \draw[-latex] (3,0)--(3,1) node[above]{\itshape z};
  \orbital[pos = {(3,0)}]{px} 
  \node[above] at (3.7,0.7) {p$_y$};

  \draw[-latex] (6,0)--(7,0) node[above]{\itshape x};
  \draw[-latex] (6,0)--(5.5,-0.7) node[above]{\itshape y};
  \draw[-latex] (6,0)--(6,1) node[above]{\itshape z};
  \orbital[pos = {(6,0)}]{pz}
  \node[above] at (6.7,0.7) {p$_z$};
  \end{tikzpicture}
  \caption{Test} \end{figure}

\end{document}

有没有什么办法?

答案1

问题很简单:tikzorbital使用该background图层。这意味着您的几幅画作位于同一图层上。

您可以通过声明另一个层并将其设置在当前background层后面来解决该问题。这可以使用\pgfdeclarelayer\pgfsetlayer命令来完成。

代码:

\documentclass{article}

\usepackage[x11names]{xcolor}
\usepackage{tcolorbox}% no need in this mwe
\usepackage[font=small]{caption}% no need in this mwe
\usepackage{float}% no need in this mwe
\usepackage{floatflt}% no need in this mwe

\usepackage{tikz} 
\usepackage{tikzorbital}
\usetikzlibrary{fadings,patterns,backgrounds,fit,arrows}
\pgfdeclarelayer{backbackground}
\pgfsetlayers{backbackground,background,main}

\begin{document}

\begin{figure}[ht!]
  \centering
  \begin{tikzpicture}
  \begin{scope}[font=\itshape]% to not type it every time, but better go for math mode
  \draw[-latex] (0,0)--(1,0) node[above]{x};
  \draw[-latex] (0,0)--(-0.5,-0.7) node[above]{y};
  \draw[-latex] (0,0)--(0,1) node[above]{z};
  \orbital[pos = {(0,0)}]{py}
  \node[above] at (0.7,0.7) {p$_x$};

  \draw[-latex] (3,0)--(4,0) node[above]{x};
  \draw[-latex] (3,0)--(2.5,-0.7) node[above]{y};
  \draw[-latex] (3,0)--(3,1) node[above]{z};
  \orbital[pos = {(3,0)}]{px} 
  \node[above] at (3.7,0.7) {p$_y$};

  \draw[-latex] (6,0)--(7,0) node[above]{x};
  \draw[-latex] (6,0)--(5.5,-0.7) node[above]{y};
  \draw[-latex] (6,0)--(6,1) node[above]{z};
  \orbital[pos = {(6,0)}]{pz}
  \node[above] at (6.7,0.7) {p$_z$};
  \end{scope}

  % correctly setting the background layer
  \begin{pgfonlayer}{backbackground}
  \fill[LightBlue1](current bounding box.south west)rectangle
  (current bounding box.north east);
  \end{pgfonlayer}
  \end{tikzpicture}
  \caption{Test} \end{figure}

\end{document}

结果:

在此处输入图片描述

相关内容