5

It looks like tikzorbital package is not compatible with background library of basic TikZ. As you see in the picture below, just p_y displayed (do not pay attention to notations in MWE). It displays everything if you switch off the background.

enter image description here

The MWE is...

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

Is there any ways around?

7

The problem is quite simple: tikzorbital makes itself use of the background layer. This means that a couple of your drawings are on the same layer.

You can solve the problem by declaring a further layer and set it behind the background one. This can be done with \pgfdeclarelayer and \pgfsetlayer commands.

The code:

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

The result:

enter image description here

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.