TikZ Diagrams – How to Put a Node Behind Another

diagramsnodestikz-pgf

I want to place a node, that is kind of a note, behind another node.
However, I need to put the reference node before the note, so I can place the note in a relative position to the reference node. So, the reference node is draw behind the note. But I want the reverse.

For example, in this figure the note is over the node. However, I want it below of the decision node.

  • So, how can I place the note behind the reference. Or is there a way to put notes to the nodes natively in TikZ?
  • The other thing is, why the text in the note is not centered?

diagram

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shadows,positioning}

\begin{document}
\tikzstyle{decision} = [diamond, draw, fill=blue!5, text width=6em, text badly centered, node distance=2.5cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!5,
    text width=7em, text centered, rounded corners, minimum height=4em]
\tikzstyle{note} = [rectangle, dashed, draw, fill=white, font=\footnotesize,
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, very thick, color=black!50, -latex']
\begin{tikzpicture}[scale=2, node distance = 2cm, auto]
  \node [block] (blk) {A block here};
  \node [decision, below of=blk] (if) {Is something?};
  \node [note,below right=-5mm of if, anchor=north west] (note1) {using a note here};
  \path [line] (blk) -- (if);
\end{tikzpicture}
\end{document}

Best Answer

A variant of Azoun's solution is to use the backgrounds tikz library. The code is

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,shadows,positioning}
\usetikzlibrary{backgrounds}

\begin{document}

\tikzstyle{decision} = [diamond, draw, fill=blue!5, text width=6em, text badly centered, node distance=2.5cm, inner sep=0pt]

\tikzstyle{block} = [rectangle, draw, fill=blue!5,
    text width=7em, text centered, rounded corners, minimum height=4em]

\tikzstyle{note} = [rectangle, dashed, draw, fill=white, font=\footnotesize,
    text width=5em, text centered, rounded corners, minimum height=4em]

\tikzstyle{line} = [draw, very thick, color=black!50, -latex']

\begin{tikzpicture}[scale=2, node distance = 2cm, auto]
  \node [block] (blk) {A block here};
  \node [decision, below of=blk] (if) {Is something?};

  \begin{scope}[on background layer]
    \node [note,below right=-5mm of if, anchor=north west, text width=2cm] (note1) {using a note here};
  %you may also use align = center instead of text width = ...
  \end{scope}

  \path [line] (blk) -- (if);
\end{tikzpicture}
\end{document}