Make `append after command` draw something behind the text of a node

tikz-pgf

The context

I know how to use append after command to draw a cross inside a rectangle (see code block and image below)

\documentclass[border=2]{standalone}

\usepackage{tikz}

\usetikzlibrary{shapes.misc, fit}

\tikzset{
  mystyle/.style = {
    rectangle,
    draw,
    append after command={
      node [
        fit = (\tikzlastnode),
        inner sep = -\pgflinewidth,
        cross out,
        draw = blue
      ] {}
    }
  },
}

\begin{document}
\begin{tikzpicture}

  \node [mystyle] {a};

\end{tikzpicture}
\end{document}

a node with a rectangle border with "a" as the text inside the node and a cross inside the rectangle but above the text

As can be seen in the image above, the blue cross is drawn on top of the text of the node. I want to change this behavior. I want the text to be on top of the blue cross so that text is not covered by anything.

The question

How can I make the text of the node not be covered by the blue cross drawn by append after command?

One way to accomplish this is by making append after command draw the cross below the "a". Is there an option that I can pass to append after command to set that behavior?

Best Answer

You can customize the node "background" with a path picture:

enter image description here

\documentclass[border=2]{standalone}
\usepackage{tikz}

\tikzset{
    mybg/.style={
        path picture={
            \draw[blue] (path picture bounding box.north west) -- (path picture bounding box.south east)
            (path picture bounding box.north east) -- (path picture bounding box.south west);
        }
    },
}

\begin{document}
\begin{tikzpicture}
    \node [draw,mybg] {a};
\end{tikzpicture}
\end{document}