我想将一个节点拟合到另一个节点,该节点定义在不同的范围中,并且已受选项“(x)shift and transform canvas”约束(参见示例代码和图像)。没有任何画布或移位操作,拟合工作如预期。但是,使用变换画布选项时,拟合不起作用。如何获取节点的“世界坐标”,即应用所有范围修改后的坐标?
代码:
\documentclass[a5paper]{article}
\pagenumbering{gobble}
\usepackage{tikz}
\usetikzlibrary{fit}
\usepackage[paperwidth=8cm,paperheight=12cm]{geometry}
\begin{document}
\section*{Without Canvas Transform}
\begin{tikzpicture}
\begin{scope}
\node[ultra thick, draw, blue, minimum width=2cm, circle, xshift=15] (n1) {};
\end{scope}
\begin{scope}
\node[thick, fill opacity=0.3, fill=yellow, draw, inner sep=0, yellow, fit=(n1)] (n2) {};
\end{scope}
\end{tikzpicture}
\section*{With Canvas Transform}
\vspace{10pt}
\begin{tikzpicture}
\begin{scope}[transform canvas={scale=1.5}, xshift=15]
\node[ultra thick, draw, blue, minimum width=2cm, circle] (n1) {};
\end{scope}
\begin{scope}
\node[thick, fill opacity=0.3, fill=yellow, draw, inner sep=0, yellow, fit=(n1)] (n2) {};
\end{scope}
\end{tikzpicture}
\end{document}
答案1
变换画布是一种硬核变换,不考虑任何边界框计算或类似的良好更新。因此,它像老板一样变换。在这里,我们在评论中得出结论,您希望节点尊重范围内的内部变换。这是通过即transform shape
节点的形状也会被变换来完成的。
\documentclass[a5paper]{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
\begin{scope}[scale=1.5,xshift=15]
\node[ultra thick, draw, blue, minimum width=2cm, circle,transform shape] (n1) {};
\end{scope}
\node[thick, fill opacity=0.3, fill=yellow, draw, inner sep=0, yellow, fit=(n1)] (n2) {};
\end{tikzpicture}
\end{document}