circle through
下面是一个 MWE,展示了当我尝试使用缩放转换(和)时遇到的挑战transform shape
:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\coordinate[label=left:A] (A) at (0,0);
\coordinate[label=right:B] (B) at (1,0);
\draw (A) -- (B);
\node[draw,circle through=(B)] at (A) {};
\node[draw,circle through=(A)] at (B) {};
\begin{scope}[xshift=3cm, scale=.75, transform shape]
\coordinate[label=left:A] (A) at (0,0);
\coordinate[label=right:B] (B) at (1,0);
\draw (A) -- (B);
\node[draw,circle through=(B)] at (A) {};
\node[draw,circle through=(A)] at (B) {};
\end{scope}
\end{tikzpicture}
\end{document}
它会给出如下图表:
经过这样的缩放,虽然节点 A 和 B 都调整了大小,但它们不再位于圆上。 似乎有些操作的顺序是错误的。
顺便说一句,我知道我总是可以使用“calc”库来计算半径,然后绘制圆,但我希望我不需要以这种方式解决这个问题。有什么想法或解决方案吗?
答案1
我认为你应该transform canvas
在这种情况下使用。(更新:调整线宽。)
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\coordinate[label=left:A] (A) at (0,0);
\coordinate[label=right:B] (B) at (1,0);
\draw (A) -- (B);
\node[draw,circle through=(B)] at (A) {};
\node[draw,circle through=(A)] at (B) {};
\begin{scope}[xshift=4cm]
\begin{scope}[transform canvas={scale=.75},line width=1.33\pgflinewidth] %, transform shape
\coordinate[label=left:A] (A) at (0,0);
\coordinate[label=right:B] (B) at (1,0);
\draw (A) -- (B);
\node[draw,circle through=(B)] at (A) {};
\node[draw,circle through=(A)] at (B) {};
\end{scope}
\end{scope}
\path (A) --++(0.6,0);
\end{tikzpicture}
\end{document}
有时这会搞乱边界框,这就是为什么我在最后添加了路径。
答案2
@Kpym 提供了一个注释,可以同时缩放图形和标签字体大小,这正是我们想要的结果。下面是根据他的建议编写的 MWE,它解决了这个问题:
scale=0.75
在图中将所有坐标乘以 0.75。此缩放实际上是在之前完成的circle through
,因此仍然通过给定的点绘制圆圈。对象(包括文本字体大小)不会在此处缩放。因此,我们需要以下命令来帮助缩放文本字体大小。every label/.style={transform shape}
确保标签(即“A”和“B”)的字体大小在相同的缩放系数 0.75 下缩放。
MWE 代码:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{through}
\begin{document}
\begin{tikzpicture}
\coordinate[label=left:A] (A) at (0,0);
\coordinate[label=right:B] (B) at (1,0);
\draw (A) -- (B);
\node[draw,circle through=(B)] at (A) {};
\node[draw,circle through=(A)] at (B) {};
\begin{scope}[xshift=3cm, scale=.75, every label/.style={transform shape}]
\coordinate[label=left:A] (A) at (0,0);
\coordinate[label=right:B] (B) at (1,0);
\draw (A) -- (B);
\node[draw,circle through=(B)] at (A) {};
\node[draw,circle through=(A)] at (B) {};
\end{scope}
\end{tikzpicture}
\end{document}