7

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};
...
  • 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 '15 at 8:49
  • 2
    Have a look at the fit library. – Pier Paolo Jun 21 '15 at 8:49
  • 2
    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
10

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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