pgf-tikz / pgf

A Portable Graphic Format for TeX
https://pgf-tikz.github.io/
1.15k stars 109 forks source link

pgfonlayer in tikz matrix #1282

Open tobiasBora opened 1 year ago

tobiasBora commented 1 year ago

Brief outline of the bug

\begin{pgfonlayer} cannot be used inside a matrix. If I try, the node is completely misplaced:

image

Soo also https://tex.stackexchange.com/questions/618823/node-on-layer-style-in-tikz-matrix-tikzcd

Minimal working example (MWE)

\documentclass[]{article}

\usepackage{tikz}

\begin{document}

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}   %% some additional layers for demo

\begin{tikzpicture}
  \node [matrix] (my matrix) at (2,1)
  {
    \node[fill=pink,name=hello]{Hello}; & \node{A}; \\
    \node{B};                           & \node[fill=green,name=bye]{Bye}; \\
  };
  \draw[very thick, red] (hello.center) -- (bye.center);
\end{tikzpicture}

Adding pgfonlayer only: I would expect the line to be above Hello, but below Bye. Instead, the node is completely misplaced:

\begin{tikzpicture}
  \node [matrix] (my matrix) at (2,1)
  {
    \node[fill=pink,name=hello]{Hello}; & \node{A};\\
    \node{B}; &
    \begin{pgfonlayer}{foreground}
      \node[fill=green,name=bye]{Bye};
    \end{pgfonlayer}
    \\
  };
  \draw[very thick, red] (hello.center) -- (bye.center);
\end{tikzpicture}

\end{document}