Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following two tikzpicture, where the second needs the overlay. However, with that option, the line drawn from A to C goes through B, despite the \begin{pgfonlayer}{back}…\end{pgfonlayer}. What can I do to make the line appear below B (appart from redrawing B after, which is not practical since it has a random xshift and yshift).

minimal example

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

A more complete example justifying the use of remember picture and overlay:

Complete example

\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}
share|improve this question

1 Answer 1

up vote 8 down vote accepted

The layers are local to each picture. In other words: your onlayer statement has no effect; you would need to separate layers inside of a single picture.

share|improve this answer
    
Ah, that explains it. I'll wait a little to see if someone provides a workaround, otherwise I'll accept your solution. Thanks for the information. –  Georges Dupéron Aug 31 '12 at 21:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.