图层在“覆盖”图片中不起作用

图层在“覆盖”图片中不起作用

我有以下两个tikzpicture,其中第二个需要overlay。但是,使用该选项,尽管有,从A到绘制的线C仍会穿过。我该怎么做才能使线出现在 B 下方(除了之后重新绘制 B,这并不实用,因为它具有随机的 xshift 和 yshift)。B\begin{pgfonlayer}{back}…\end{pgfonlayer}

最小示例

\documentclass{article}
\usepackage{tikz}
\pgfdeclarelayer{back}
\pgfsetlayers{back,main}
\begin{document}

\begin{tikzpicture}[remember picture]
  \node[draw=red!50,  fill=red!10]   (A) at (0,0) {A};
  \node[draw=green!50,fill=green!10] (B) at (1,0) {B};
  \node[draw=blue!50, fill=blue!10]  (C) at (2,0) {C};
\end{tikzpicture}

\begin{tikzpicture}[remember picture, overlay]
  \begin{pgfonlayer}{back}
    \draw (A) -- (C);
  \end{pgfonlayer}
\end{tikzpicture}

\end{document}

remember picture一个更完整的例子来证明和的使用overlay

完整示例

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,chains,trees}
\pgfdeclarelayer{back}
\pgfsetlayers{back,main}
\begin{document}

\begin{figure}[h]
  \centering
  \begin{tikzpicture}[remember picture]
    \matrix[matrix of nodes, every node/.style={anchor=center}] {
      \begin{tikzpicture}[start chain=going below, every node/.style={on chain}]
        \node[draw=red!50,  fill=red!10]   (A1) {A};
        \node[draw=red!50,  fill=red!10]   (A2) {AA};
        \node[draw=red!50,  fill=red!10]   (A3) {AAA};
      \end{tikzpicture} &
      \begin{tikzpicture}[grow cyclic, sibling angle=360/7, edge from parent/.style={draw=none}]
        \node {} child foreach \i in {1,...,7} {
          node[draw=green!50,fill=green!10] {B\i};
        };
      \end{tikzpicture} &
      \begin{tikzpicture}[start chain=going below, every node/.style={on chain}]
        \node[draw=blue!50, fill=blue!10]  (C1) {C};
        \node[draw=blue!50, fill=blue!10]  (C2) {C};
      \end{tikzpicture} \\
      Label A & Label B & Label C\\
    };
  \end{tikzpicture}
  \caption{Foo}
\end{figure}

\begin{tikzpicture}[remember picture, overlay]
  \begin{pgfonlayer}{back}
    \draw[thick] (A1) -- (C2);
  \end{pgfonlayer}
\end{tikzpicture}

\end{document}

答案1

图层是每个图片的本地图层。换句话说:您的 onlayer 语句无效;您需要在单身的图片。

相关内容