TikZ PGF – Inconsistent Behavior of TikZ [fit] and [transform shape]

tikz-pgftikzscale

I want to frame a set of nodes with the option [fit] ​​and change the overall size of the drawing with [scale = xx, transform shape] but I have unexpected behavior. the frame is no longer valid

the code:

\documentclass[a4paper]{article}                

\usepackage{pgf,tikz}
\usetikzlibrary{fit,calc,positioning}

\begin{document}

\begin{tikzpicture}
\node[draw](A){A};
\node[right=3em of A,draw](B){B};
\node[left=3em of A,draw](C){C};
\node[above=3em of A,draw](D){D};
\node[below=3em of A,draw](E){E};
\node[fit=(A) (B) (C) (D) (E), draw]{};
\end{tikzpicture}
\hfill
\begin{tikzpicture}[scale=0.8,transform shape]
\node[draw](A){A};
\node[right=3em of A,draw](B){B};
\node[left=3em of A,draw](C){C};
\node[above=3em of A,draw](D){D};
\node[below=3em of A,draw](E){E};
\node[fit=(A) (B) (C) (D) (E), draw]{};
\end{tikzpicture}

\end{document}

enter image description here

what can I do?, is this a bug?

Best Answer

You have to exclude the fitting node to be scaled since it first fits the contents and then applies the scaling to it again. Easiest is to turn off the transfrom shape effect.

\documentclass[a4paper]{article}                

\usepackage{tikz}
\usetikzlibrary{fit,calc,positioning}

\begin{document}

\begin{tikzpicture}
\node[draw](A){A};
\node[right=3em of A,draw](B){B};
\node[left=3em of A,draw](C){C};
\node[above=3em of A,draw](D){D};
\node[below=3em of A,draw](E){E};
\node[fit=(A) (B) (C) (D) (E), draw]{};
\end{tikzpicture}
\begin{tikzpicture}[scale=0.5,transform shape]
\node[draw](A){A};
\node[right=3em of A,draw](B){B};
\node[left=3em of A,draw](C){C};
\node[above=3em of A,draw](D){D};
\node[below=3em of A,draw](E){E};
\node[fit=(A) (B) (C) (D) (E), transform shape=false,draw]{};
\end{tikzpicture}

\end{document}

enter image description here