# Draw rectangle around nodes with tikz

I have a lot of nodes placed with tikz. Now I need to draw an rectangle around all these nodes.

I can draw the rectangle manually with

\draw [fill=gray!5] (2, -6) rectangle (18, 6.5)
(2, 6.5) node[below right,fill,draw] {Rectangle Title};


All my nodes are named and placed relatively:

...
\node [below=5cm of nodeA] (nodeB) {Node B text};
...

• Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Jun 21 '15 at 8:49
• Have a look at the fit library. – Pier Paolo Jun 21 '15 at 8:49
• Look at TikZ library fit (p.630, pgfmanual)... – Paul Gaborit Jun 21 '15 at 8:49
• Pick the two nodes, one in the lower left and one in the upper right, and use the fit library. This seems to be the best solution but it might be different if we saw your code. – Alenanno Jun 21 '15 at 8:54
• Some examples for the fit library: how to draw a container box in latex around automata? Tikz - How to Draw Boxes Around Set of Nodes – Torbjørn T. Jun 21 '15 at 8:54

Let suppose, that your nodes have names. Among them are most outside northernmost, southernmost, easternmost and westernmost. In this case, as above comments say, the simple solution is:
• in preamble put TikZ library fit
• in your TikZ picture use \node[draw,inner sep=2mm,label=below:Rectangle Title,fit=(northernmost) (southernmost) (easternmost) (westernmost)] {};