tikz [fit] 和 [transform shape] 行为不一致

tikz [fit] 和 [transform shape] 行为不一致

我想用选项 [fit] 框住一组节点,并用 [scale=xx,transform shape] 更改绘图的整体大小,但我遇到了意外行为。框架不再有效

代码:

\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}

在此处输入图片描述

我该怎么办?这是一个错误吗?

答案1

您必须排除要缩放的拟合节点,因为它首先拟合内容,然后再次对其应用缩放。最简单的方法是关闭效果transfrom shape

\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}

在此处输入图片描述

相关内容