# TIkZ: fit clipped nodes

I would like to draw a box that encloses several shapes using the fit option. But when some shapes are clipped, fit still takes the whole shape into.

Here is a minimal working example.

\documentclass{standalone}
\usepackage{tikz}

\usetikzlibrary{fit,positioning}

\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-1cm, -1cm) rectangle ++(1cm, 2cm);
\node [draw, circle, minimum size=2cm] (A) {};
\end{scope}
\begin{scope}[xshift=1cm]
\clip (-1cm, -1cm) rectangle ++(1cm, 2cm);
\node [draw, circle, minimum size=2cm] (B) {};
\end{scope}
\node [draw=blue, line width=1mm, inner sep=1mm, rectangle, fit=(A) (B)] {};
\end{tikzpicture}
\end{document}


And the result.

Is there a way to fit better my shapes?

Since those scope environments are generated automatically (with an append after command option) I'd like to keep them as similar as possible. Other than that, I'd take any solution.

Just fit the B.center

\node [draw=blue, line width=1mm, inner sep=1mm, rectangle, fit=(A) (B.center)] {};


Code:

\documentclass{standalone}
\usepackage{tikz}

\usetikzlibrary{fit,positioning}

\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-1cm, -1cm) rectangle ++(1cm, 2cm);
\node [draw, circle, minimum size=2cm] (A) {};
\end{scope}
\begin{scope}[xshift=1cm]
\clip (-1cm, -1cm) rectangle ++(1cm, 2cm);
\node [draw, circle, minimum size=2cm] (B) {};
\end{scope}
\node [draw=blue, line width=1mm, inner sep=1mm, rectangle, fit=(A) (B.center)] {};
\end{tikzpicture}
\end{document}


• Awesome! How couldn't I think about that? BTW, I think you left a use as bounding box option as a part of a previous test. :) – Celelibi Feb 21 '15 at 2:00
• @Celelibi Yes, now corrected. :-) – user11232 Feb 21 '15 at 2:04