You can make use of the fit
-library. You can pass the nodes you want to include to the fit
-option and put the fitting-node on the background layer.
In your example it is sufficient to fit the three outermost nodes to get the fitting-node into the right position:
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds, fit}
\begin{document}
\tikzstyle{block}=[fill=white,draw=red,minimum size=1.5cm, rounded corners,align=center]
\begin{tikzpicture}
\node[block] (2D) {$2$D\\Histogramm};
\node[draw=none,left of=2D,node distance=3cm] (dummy) {};
\node[block,above of=dummy,node distance=1cm] (E) {E\\signal};
\node[block,below of=dummy,node distance=1cm] (DE) {$\Delta$E\\signal};
\node[block,right of=2D,node distance=3cm] (region) {$p$ signal\\selection};
\node[block,right of=region,node distance=3cm] (projection) {E detector\\projection};
\node[block,right of=projection,node distance=3cm] (smoothing) {smoothing};
\node[block,right of=smoothing,node distance=3cm] (rebinning) {rebinning};
\begin{scope}[on background layer]
\node [fit=(E) (DE) (rebinning), fill= gray!30, rounded corners, inner sep=.5cm] {};
\end{scope}
\end{tikzpicture}
\end{document}

This way you also can easily add a label-text to your background node using:
\node [fit=..., label={<position>:Your label text here}] {};
Where <position>
is the angle/position where your label gets positioned (e.g. above
, below
, -45
, ...). For more information about this have a look at the pgfmanual
.
EDIT: Approach using relative coordinates (see comments)
To get your above code working the way you wrote it, you can make use of the calc
-library and calculate the points of the rectangle.
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds, calc}
\begin{document}
\tikzstyle{block}=[fill=white,draw=red,minimum size=1.5cm, rounded corners,align=center]
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\begin{tikzpicture}
\node[block] (2D) {$2$D\\Histogramm};
\node[draw=none,left of=2D,node distance=3cm] (dummy) {};
\node[block,above of=dummy,node distance=1cm] (E) {E\\signal};
\node[block,below of=dummy,node distance=1cm] (DE) {$\Delta$E\\signal};
\node[block,right of=2D,node distance=3cm] (region) {$p$ signal\\selection};
\node[block,right of=region,node distance=3cm] (projection) {E detector\\projection};
\node[block,right of=projection,node distance=3cm] (smoothing) {smoothing};
\node[block,right of=smoothing,node distance=3cm] (rebinning) {rebinning};
\begin{pgfonlayer}{background}
\draw[fill=gray!30,rounded corners] ($(DE.south west) +(-0.5,-0.5)$) rectangle ($(rebinning.north east) +(1,1.5)$);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
EDIT: To sum up the comments and the information from this answer:
- Using
fit
- Using
positioning
- Using node-label on background-node
Code:
\documentclass[tikz, border=5mm]{standalone}
\usetikzlibrary{backgrounds, positioning, fit}
\begin{document}
\begin{tikzpicture}
\tikzset{
block/.style={
draw=red,
fill=white,
minimum size=1.5cm,
rounded corners,
align=center,
},
}
\node[block] (2D) {$2$D\\Histogramm};
\node[block, above left=-.5cm and 1cm of 2D] (E) {E\\signal};
\node[block, below left=-.5cm and 1cm of 2D] (DE) {$\Delta$E\\signal};
\node[block, right=of 2D] (region) {$p$ signal\\selection};
\node[block, right=of region] (projection) {E detector\\projection};
\node[block, right=of projection] (smoothing) {smoothing};
\node[block, right=of smoothing] (rebinning) {rebinning};
\begin{scope}[on background layer]
\node [fit=(E) (DE) (rebinning), fill= gray!30, rounded corners, inner sep=.5cm, label={[red]below:Your label text here}] {};
\end{scope}
\end{tikzpicture}
\end{document}
Rendered image:

fit
library for this. – Claudio Fiandrino Sep 5 '14 at 7:30(E.north west)+(-0.5,0.5)
you can use([shift={(-0.5,0.5)}]E.north west)
. Note{
and}
when usingshift
. They are not necessary when usingxshift
oryshift
. – Ignasi Sep 5 '14 at 7:42rectangle
operation takes into account the first coordinate it encounters after the key, so the trick to make your code working would be\draw[fill=gray!30,rounded corners] (E.north west)+(-0.5,0.5)rectangle($(rebinning.south east)+(1,-2)$);
(with a -2, not plus). – Claudio Fiandrino Sep 5 '14 at 7:42