2

Current question related with my other question, TikZ and tikzorbital: problem with background. In prevous question, the problem with layers has been decided:

enter image description here

All I need is just fill rectangle width becomes to \columnwidth. If you are interesting, why I need it, I use the filled caption, and I need booth picture fill width and caption fill width becomes to \columnwidth. However you don't need to create the filled caption in MWE: use the text as measure.

enter image description here

\documentclass[a4paper]{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}

\usepackage{lipsum} 

\oddsidemargin=-10.4mm  %     
\evensidemargin=-20.4mm %
\topmargin=-24mm        %
\textwidth=190mm        %
\textheight=275mm       %
\headheight = 5mm      %
\headsep = 4mm
\footskip = 8mm

\begin{document}
\twocolumn

\lipsum[1-2]

\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{This is the test of the caption} \end{figure}

\lipsum[3-7]

\end{document}
1

You can add a dummy node with a minimum width=\columnwidth to fill across the column. Similarly, enclose the caption inside a node with some adjustments. On the other hand, if you are loading caption package, you may use \captionof macro too.

\documentclass[a4paper]{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}

\usepackage{lipsum}

\oddsidemargin=-10.4mm  %
\evensidemargin=-20.4mm %
\topmargin=-24mm        %
\textwidth=190mm        %
\textheight=275mm       %
\headheight = 5mm      %
\headsep = 4mm
\footskip = 8mm

\begin{document}
\twocolumn

\lipsum[1-2]

\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}
  \node[minimum width=\columnwidth] at (current bounding box.center){};   %% this node is dummy

  % 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}
  \tikz[baseline=1ex]\node[text width=\columnwidth,fill=LightBlue1,text height=-2ex,inner sep=0pt]{\caption{This is the test of the caption This is the test of the caption This is the test of the caption}};   %% caption inside a node.
  \end{figure}

\lipsum[3-7]

\end{document}

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.