TikZ 拟合库对变换形状感到困惑?

TikZ 拟合库对变换形状感到困惑?

使用 with 时,fit 库似乎缺少了一点transform shape

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}[]
    \node[draw] (a) at (0,0) {A};
    \node[draw] (b) at (1,1) {B};
    \node[draw] (c) at (-1,1) {C};
    \node[draw, red, fit =(a) (b) (c)]{};
\end{tikzpicture}
\begin{tikzpicture}[scale=0.7, transform shape]
    \node[draw] (a) at (0,0) {A};
    \node[draw] (b) at (1,1) {B};
    \node[draw] (c) at (-1,1) {C};
    \node[draw, red, fit =(a) (b) (c)]{};
\end{tikzpicture}
\end{document}

结果(版本 3.0.1a,随 Ubuntu 18.04LTS 一起提供)

带有未对齐节点的输出

这是正常的吗?除了手动调整外,还有什么办法可以避免这种情况吗inner sep

答案1

最终该问题已在版本中得到修复3.1.3,并得到了正确的行为。

然而,问题似乎如果你使用,就会回来rotate,正如所注意到的@薛定谔的猫在评论中(现已删除):

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}[]
    \node[draw] (a) at (0,0) {A};
    \node[draw] (b) at (1,1) {B};
    \node[draw] (c) at (-1,1) {C};
    \node[draw, red, fit =(a) (b) (c), inner sep=0pt]{};
\end{tikzpicture}
\begin{tikzpicture}[scale=0.7, rotate=45, transform shape]
    \node[draw] (a) at (0,0) {A};
    \node[draw] (b) at (1,1) {B};
    \node[draw] (c) at (-1,1) {C};
    \node[draw, red, fit =(a) (b) (c), inner sep=0pt]{};
\end{tikzpicture}
\end{document}

在此处输入图片描述

...尽管这是意料之中的,因为手册指出fit只考虑了北、南、东和西锚点。此行为可以通过以下方法修复:

\node[draw, red, fit =(a) (b) (c)
            (a.north west) (a.south west) (a.south east) (a.north east)
            (b.north west) (b.south west) (b.south east) (b.north east)
            (c.north west) (c.south west) (c.south east) (c.north east),
            inner sep=0pt]{};

这使:

在此处输入图片描述

相关内容