当节点形状为圆形时,“inner sep” 到底是什么意思

当节点形状为圆形时,“inner sep” 到底是什么意思

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 sepinner xsepinner 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. 的评论,他讲了完全一样的话。抱歉重复了。

相关内容