![TikZ 节点标签未放置在我想要的位置](https://linux22.com/image/275603/TikZ%20%E8%8A%82%E7%82%B9%E6%A0%87%E7%AD%BE%E6%9C%AA%E6%94%BE%E7%BD%AE%E5%9C%A8%E6%88%91%E6%83%B3%E8%A6%81%E7%9A%84%E4%BD%8D%E7%BD%AE.png)
为什么以下 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}