12

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};
...
5
  • 2
    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, 2015 at 8:49
  • 2
    Have a look at the fit library.
    – Pier Paolo
    Jun 21, 2015 at 8:49
  • 2
    Look at TikZ library fit (p.630, pgfmanual)... Jun 21, 2015 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, 2015 at 8:54

1 Answer 1

16

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)] {};

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .