inner sep
表现不如我预期:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[every node/.style={circle,draw}]
\coordinate (P1) at (0,0);
\coordinate (P2) at ($(P1)+(30:2cm)$);
%% first circle
%% separation along x-, y- directions is greater than 2cm.
\node [inner sep=2cm,orange,line width=3pt] at (P1) {};
%% second circle
%% separation along x-, y- directions is as expected
\node [inner xsep=2cm,blue!30,line width=2pt] at (P1) {};
%% third circle
%% duplicates the situation of the first circle. Again
%% the separation along axes is greater than expected.
\node [inner xsep=2cm,
inner ysep=2cm,yellow,line width=1pt] at (P1) {};
\draw (P1) circle [radius=2cm,draw,magenta];
\draw (P1) -- (P2);
\draw[help lines] (-4,-4) grid (4,4);
\end{tikzpicture}
\end{document}
根据的文档inner sep
,inner xsep
我inner ysep
希望使用欧几里得度量而不是出租车度量来测量距离。
有人能解释一下这里发生了什么吗?为什么这是理想的行为
答案1
该circle
形状是标准形状的外接圆rectangle
。因此,如果您希望此圆的半径为 2cm,则必须将矩形的一个长度设置为 2cm,另一个长度设置为 0cm。
\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[every node/.style={draw, very thick}]
\path (0,0) coordinate (P1) +(30:2cm) coordinate (P2);
%% first circle
%% fitting square 2cmx2cm
\node [inner sep=2cm, green] at (P1) {};
\node [circle, inner sep=2cm, green] at (P1) {};
%% second circle
%% fitting square 2cmx0cm
\node [inner xsep=2cm, inner ysep=0cm, red] at (P1) {};
\node [circle, inner xsep=0cm, inner ysep=2cm, red] at (P1) {};
\draw (P1) circle [radius=2cm, draw, magenta];
\draw (P1) -- (P2);
\draw[help lines] (-3,-3) grid (3,3);
\end{tikzpicture}
\end{document}
编辑 :我看到了 Torbjørn T. 的评论,他讲了完全一样的话。抱歉重复了。