为什么以下 MWE 没有按照正确的角度放置标签?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[every path/.style={line width=1pt}]
\coordinate (X) at (2,4) {};
\foreach \x in { 100,107,114}
{
\node (tmp\x) at ($(X)+(\x:3)$) {};
\draw[orange!30,fill=orange!30] (X) -- (tmp\x);
}
\node[circle,inner sep=2pt,draw,label=107:X] at (X) {};
\node[inner sep=0pt,fill=none] (label/A) at ($(X)+(107:1.0)$) {Y};
\end{tikzpicture}
\end{document}
已Y
被放置在我期望和想要的位置X
。
答案1
节点label
仅以 45° 的步长放置,类似于使用该auto
选项放置的节点。
您可以通过重新定义负责捕捉行为的内部宏来禁用此功能并获得度数精度。
以下代码(取自https://tex.stackexchange.com/a/85669/2552) 的作用是:
\makeatletter
\def\tikz@auto@anchor{%
\pgfmathtruncatemacro\angle{atan2(\pgf@x,\pgf@y)-90}
\edef\tikz@anchor{\angle}%
}
\def\tikz@auto@anchor@prime{%
\pgfmathtruncatemacro\angle{atan2(\pgf@x,\pgf@y)+90}
\edef\tikz@anchor{\angle}%
}
\makeatother
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\makeatletter
\def\tikz@auto@anchor{%
\pgfmathtruncatemacro\angle{atan2(\pgf@x,\pgf@y)-90}
\edef\tikz@anchor{\angle}%
}
\def\tikz@auto@anchor@prime{%
\pgfmathtruncatemacro\angle{atan2(\pgf@x,\pgf@y)+90}
\edef\tikz@anchor{\angle}%
}
\makeatother
\begin{tikzpicture}[every path/.style={line width=1pt}]
\coordinate (X) at (2,4) {};
\foreach \x in { 100,107,114}
{
\node (tmp\x) at ($(X)+(\x:3)$) {};
\draw[orange!30,fill=orange!30] (X) -- (tmp\x);
}
\node[circle,inner sep=2pt,draw,label=107:X] at (X) {};
\node[inner sep=0pt,fill=none] (label/A) at ($(X)+(107:1.0)$) {Y};
\end{tikzpicture}
\end{document}